Selaa lähdekoodia

missing stations migration

Gamaliel Espinoza 8 vuotta sitten
vanhempi
commit
2e733fc05c
2 muutettua tiedostoa jossa 24 lisäystä ja 1 poistoa
  1. 1 1
      tools/fourier/__init__.py
  2. 23 0
      tools/fourier/cli.py

+ 1 - 1
tools/fourier/__init__.py

@@ -1 +1 @@
-__version__ = '1.0.4'
+__version__ = '1.0.5'

+ 23 - 0
tools/fourier/cli.py

@@ -15,6 +15,7 @@ import time
 import json
 import sys
 import os
+import re
 
 
 strptime = datetime.strptime
@@ -197,6 +198,28 @@ def main():
 
         elif action == 'connect':
             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':