#!/usr/bin/tclsh ### # # if we need a new year of data # lynx --dump --width 300 'http://finalsiren.com/Fixture.asp?TeamID=4&SeasonID=2014' > 2014.txt # # ### proc ReturnDate {f year round out} { regexp {([A-Z][a-z][a-z]) (\d+) \(.*\)$} $out m mm dd puts "$dd $mm $year" return } proc UpdateVid {f year round out h hs a as} { set hs [regsub -all {\s+} $hs { }] set as [regsub -all {\s+} $as { }] set director "AFL Round $round" set plot "$out\n\n$h $hs\n$a $as" catch {exec mplayer -vo null -ao null -frames 0 -identify $f 2>/dev/null | grep ID_LENGTH | cut -f2 -d= | tail -n1} len_s set len [expr round($len_s/60)] catch {exec echo "select intid from videometadata where filename='$f'\;" | mysql --batch -h 192.168.0.2 --user=mythtv --password=mythtv mythconverg | tail -n1 2>/dev/null} intid puts "for $f (len: $len) - (intid=$intid), add $director\n$plot" catch {exec echo "update videometadata set length='$len', director='$director', plot='$plot', coverfile='/myth/video-cover-art/gfc.jpg', year=$year where intid=$intid\;" | mysql --batch -h 192.168.0.2 --user=mythtv --password=mythtv mythconverg} } set year [lindex $argv 0] set round [lindex $argv 1] #process file of years results if { [catch {open "/home/ddp/bin/$year.txt" r} f] } { exec lynx --dump --width 300 "http://finalsiren.com/Fixture.asp?TeamID=4&SeasonID=$year" > /home/ddp/bin/$year.txt if { [catch {open "/home/ddp/bin/$year.txt" r} f] } { puts stderr "Failed to get / load year of data see comment a top of file and do it by hand" exit 1 } } while { [gets $f line] >= 0 } { if { [regexp {R(\d+)} $line m tmp_round] } { regsub -all {\[\d+\]} $line {} result set DATA($tmp_round) "$result" } if { [regexp {(.F)} $line m tmp_round] } { regsub -all {\[\d+\]} $line {} result set DATA($tmp_round) "$result" } } close $f if { ! [info exists DATA($round)] } { puts stderr "No data for $year - $round - was it a bye?" exit 2 } # if the cats lost... if { [regexp {\s+(\w+)\s+(.+)\s+dftd\s+(\w+)\s+(.+\))\s+(.+)} $DATA($round) m h hs a as out] } { # see if score doesn't start with a spc, if so this is a two word team name if { [regexp {^\d} $as m] == 0 } { if { [regexp {(\w+)\s+(.+)} $as m _a _as] } { set a "$a $_a" set as $_as } } ReturnDate $f $year $round $out if { [lindex $argv 2] == "-update" } { puts stderr "will update video too" } # if the cats won... } elseif { [regexp {\s+(\w+)\s+(.+)\s+lost to\s+(\w+)\s+(.+\))\s+(.+)} $DATA($round) m h hs a as out] } { # see if score doesn't start with a spc, if so this is a two word team name if { [regexp {^\d} $hs m] == 0 } { if { [regexp {(\w+)\s+(.+)} $hs m _h _hs] } { set h "$h $_h" set hs $_hs } } ReturnDate $f $year $round $out } else { puts "Could not parse '$DATA($round)' !!!" }