|
|
@@ -5,6 +5,7 @@ from datetime import datetime
|
|
|
import sqlite3
|
|
|
import time
|
|
|
import json
|
|
|
+import sys
|
|
|
import os
|
|
|
|
|
|
strptime = datetime.strptime
|
|
|
@@ -116,6 +117,28 @@ def main():
|
|
|
print('total files indexed: {}'.format(counter))
|
|
|
print('total files in existence: {}'.format(already_indexed))
|
|
|
print('----------------------------------')
|
|
|
+
|
|
|
+ elif action == 'setup':
|
|
|
+ if not os.path.isfile(dbpath):
|
|
|
+ conn = sqlite3.connect(dbpath)
|
|
|
+ cursor = conn.cursor()
|
|
|
+ sentences = [
|
|
|
+ """create table file(
|
|
|
+ hash text primary key,
|
|
|
+ station text,
|
|
|
+ timestamp int,
|
|
|
+ filename text,
|
|
|
+ uploaded int
|
|
|
+ )""",
|
|
|
+ "create index timestamp_index_desc on file (timestamp desc)",
|
|
|
+ "create index timestamp_index_asc on file (timestamp desc)",
|
|
|
+ ]
|
|
|
+ for query in sentences:
|
|
|
+ cursor.execute(query)
|
|
|
+ conn.commit()
|
|
|
+ else:
|
|
|
+ print('database already installed')
|
|
|
+ sys.exit(1)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|