Browse Source

Creating script to generate a db file, changing to using pickle as the format for simplicity

Kirk Trombley 5 years ago
parent
commit
06c564274e
2 changed files with 27 additions and 5 deletions
  1. 5 5
      server/app.py
  2. 22 0
      server/gendb.py

+ 5 - 5
server/app.py

@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-import json
+import pickle
 import atexit
 import datetime
 
@@ -17,16 +17,16 @@ app.config["APPLICATION_ROOT"] = "/vacation/api"
 app.url_map.strict_slashes = False
 
 try:
-    with open(DB_FILE) as infile:
-        db = json.load(infile)
+    with open(DB_FILE, "rb") as infile:
+        db = pickle.load(infile)
 except FileNotFoundError:
     db = {}
 
 
 @atexit.register
 def save_db(prefix=""):
-    with open(prefix + DB_FILE, "w") as outfile:
-        json.dump(db, outfile)
+    with open(prefix + DB_FILE, "wb") as outfile:
+        pickle.dump(db, outfile)
 
 
 def backup_db():

+ 22 - 0
server/gendb.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import sys
+import pickle
+from datetime import date, timedelta
+
+
+def days_between(start, end):
+    return [start + timedelta(i) for i in range((end - start).days + 1)]
+        
+
+def build_dict(days):
+    return {(d.month, d.day): {"__dummy_": "unknown"} for d in days}
+
+
+def parse_arg(arg):
+    return date(2020, *[int(x) for x in arg.split("/")])
+
+
+if __name__ == "__main__":
+    with open(sys.argv[3], "wb") as outfile:
+        pickle.dump(build_dict(days_between(parse_arg(sys.argv[1]), parse_arg(sys.argv[2]))), outfile)