M README => README +2 -0
@@ 18,3 18,5 @@ scripts:
unmarks each GAMEURL to be ignored by stats.tcl
* table.tcl DB-PATH
generates an html file with game info
+* pick.tcl DB-PATH
+ picks a random, unplayed, unignored game from the database
A pick.tcl => pick.tcl +34 -0
@@ 0,0 1,34 @@
+#!/bin/env tclsh
+
+package require sqlite3
+package require tcl::chan::random
+package require tcl::randomseed
+
+proc fatal {reason {code -1}} {
+ puts stderr "$argv0: fatal: $reason"
+ exit $code
+}
+
+proc usage {} {
+ global argv0
+ puts stderr "usage: $argv0 DB-PATH"
+ exit -1
+}
+if {[llength $argv] != 1} usage
+set dbpath [lindex $argv 0]
+
+if {[catch {sqlite3 db $dbpath -create false}]} {
+ fatal "can't open \"$dbpath\""
+}
+
+set unplayed [db eval {SELECT name,href FROM titles WHERE played ISNULL AND ignore = 0}]
+
+set chan [::tcl::chan::random [::tcl::randomseed]]
+binary scan [read $chan 4] i1 n
+set idx [expr { (abs($n) % ([llength $unplayed] / 2)) * 2 }]
+
+set name [lindex $unplayed $idx]
+set href [lindex $unplayed $idx+1]
+
+puts "Random pick: $name"
+puts "- $href"
M stats.tcl => stats.tcl +0 -1
@@ 1,6 1,5 @@
#!/bin/env tclsh
-package require json
package require sqlite3
proc fatal {reason {code -1}} {
M table.tcl => table.tcl +0 -1
@@ 1,6 1,5 @@
#!/bin/env tclsh
-package require json
package require sqlite3
proc fatal {reason {code -1}} {