~aleteoryx/bundlemania

ref: f15491d4b3f72d69bb27c53670f1ca851e43a639 bundlemania/mark.tcl -rwxr-xr-x 1.1 KiB
f15491d4Aleteoryx html table 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/env tclsh

package require sqlite3

proc fatal {reason {code -1}} {
  puts stderr "$argv0: fatal: $reason"
  exit $code
}


proc usage {} {
  global argv0
  puts stderr "usage: $argv0 DB-PATH ?-force? ?-timestamp TIMESTAMP? GAME-URL ?GAME-URL ...?"
  exit -1
}
if {[llength $argv] < 2} usage
set gameurls [lassign $argv dbpath]

if {[lindex $gameurls 0] == "-force"} {
  set force 1
  set gameurls [lrange $gameurls 1 end]
} else {
  set force 0
}

if {[lindex $gameurls 0] == "-timestamp"} {
  set now [lindex $gameurls 1]
  set gameurls [lrange $gameurls 2 end]
} else {
  set now [clock format [clock seconds] -format %Y%m%d]
}

if {$gameurls == {}} usage


if {[catch {sqlite3 db $dbpath -create false}]} {
  fatal "can't open \"$dbpath\""
}


foreach url $gameurls {
  if {![db exists {SELECT * FROM titles WHERE href = :url}]} {
    puts stderr "game not in database: $url"
    continue
  }
  if $force {
    db eval {
      UPDATE titles SET played = :now
        WHERE href = :url
    }
  } else {
    db eval {
      UPDATE titles SET played = :now
        WHERE href = :url AND played ISNULL
    }
  }
}