|
@@ -15,6 +15,7 @@ import time
|
|
|
import json
|
|
import json
|
|
|
import sys
|
|
import sys
|
|
|
import os
|
|
import os
|
|
|
|
|
+import re
|
|
|
|
|
|
|
|
|
|
|
|
|
strptime = datetime.strptime
|
|
strptime = datetime.strptime
|
|
@@ -197,6 +198,28 @@ def main():
|
|
|
|
|
|
|
|
elif action == 'connect':
|
|
elif action == 'connect':
|
|
|
subprocess.call(['sqlite3', dbpath])
|
|
subprocess.call(['sqlite3', dbpath])
|
|
|
|
|
+
|
|
|
|
|
+ elif action == 'add-missing-stations':
|
|
|
|
|
+ re_station = re.compile(r'^/var/fourier/[^/]+/([^/]+)')
|
|
|
|
|
+ conn = sqlite3.connect(dbpath)
|
|
|
|
|
+ cursor = conn.cursor()
|
|
|
|
|
+ cursor.execute(('select hash, filename '
|
|
|
|
|
+ 'from file '
|
|
|
|
|
+ 'where station is null'))
|
|
|
|
|
+
|
|
|
|
|
+ for row in cursor:
|
|
|
|
|
+ the_hash, filename, = row
|
|
|
|
|
+ match = re_station.match(filename)
|
|
|
|
|
+ if match:
|
|
|
|
|
+ station_code = match.group(1)
|
|
|
|
|
+ params = station_code, the_hash,
|
|
|
|
|
+ curup = conn.cursor()
|
|
|
|
|
+ curup.execute(('update "file" '
|
|
|
|
|
+ 'set "station" = ? '
|
|
|
|
|
+ 'where "hash" = ?'
|
|
|
|
|
+ ), params
|
|
|
|
|
+ )
|
|
|
|
|
+ conn.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
elif args.entity == 'station':
|
|
elif args.entity == 'station':
|