|
|
@@ -21,6 +21,7 @@ import re
|
|
|
strptime = datetime.strptime
|
|
|
ARG_DATE_FMT = '%Y-%m-%d %H:%M:%S'
|
|
|
simple_date = lambda s: strptime(s, ARG_DATE_FMT)
|
|
|
+re_station = re.compile(r'^/var/fourier/[^/]+/([^/]+)')
|
|
|
|
|
|
def find_hash(hsh, db=None):
|
|
|
cursor = db.cursor()
|
|
|
@@ -31,16 +32,21 @@ def find_hash(hsh, db=None):
|
|
|
|
|
|
def insert_file(hsh, filename, timestamp, db=None, uploaded=None):
|
|
|
cursor = db.cursor()
|
|
|
+ match = re_station.match(filename)
|
|
|
+ station = match.group(1)
|
|
|
was_uploaded = int(time.time()) if uploaded else None
|
|
|
cursor.execute("""
|
|
|
- insert into file(hash, filename, timestamp, uploaded)
|
|
|
- values(?, ?, ?, ?)
|
|
|
+ insert into file(hash, filename,
|
|
|
+ timestamp, uploaded,
|
|
|
+ station)
|
|
|
+ values(?, ?, ?, ?, ?)
|
|
|
""",
|
|
|
(
|
|
|
hsh,
|
|
|
filename,
|
|
|
int(time.mktime(timestamp.timetuple())),
|
|
|
- was_uploaded
|
|
|
+ was_uploaded,
|
|
|
+ station,
|
|
|
)
|
|
|
)
|
|
|
|
|
|
@@ -224,7 +230,6 @@ def main():
|
|
|
subprocess.call(['sqlite3', dbpath])
|
|
|
|
|
|
elif action == 'add-missing-stations':
|
|
|
- re_station = re.compile(r'^/var/fourier/[^/]+/([^/]+)')
|
|
|
conn = sqlite3.connect(dbpath)
|
|
|
cursor = conn.cursor()
|
|
|
query = ('select hash, filename '
|