]> apps.delaporte.us Git - dotfiles.git/blobdiff - bin/clerk
Debian game list helper
[dotfiles.git] / bin / clerk
index 0fa3bb402f91e61c777efce80ca3254d8327ebd3..7c7b504bb96d280146f7651811933a433fb5b729 100755 (executable)
--- a/bin/clerk
+++ b/bin/clerk
@@ -1,11 +1,12 @@
 #!/usr/bin/python
 
+import csv
+from datetime import datetime as dt
 import os
 
-DATA_DIR=os.path.expanduser('~/Journal/2026/data')
+DATA_DIR=os.path.expanduser('~/Journal/2026/Data')
 
 data_files = {}
-os.path.expanduser('~/Journal/2026/data')
 for root, _, files in os.walk(DATA_DIR):
     for file in files:
         name, ext = os.path.splitext(file)
@@ -13,8 +14,51 @@ for root, _, files in os.walk(DATA_DIR):
             data_files[name] = os.path.join(root, file)
 
 print(data_files.keys())
-choice = input()
+for idx, file in enumerate(data_files.keys()):
+    print(f"{idx} - {file}")
 
-file = data_files[choice]
+user_input = input(f"Select a file:\n").strip() or default
+key = list(data_files.keys())[int(user_input)]
+
+file = data_files[key]
 
 print(file)
+
+example_rows = []
+
+with open(file, 'r') as f:
+    reader = csv.reader(f, delimiter=',', quotechar='"')
+    fields = next(reader)  # require header row
+    for i in range(4):
+        example_rows.append(next(reader))
+
+DATE_FORMAT = '%Y-%m-%d'
+
+def today():
+    return dt.now().strftime(DATE_FORMAT)
+
+values = {}
+for key in fields:
+    default = ''
+    if key == 'date':
+        default = today()
+    user_input = input(f"{key} [{default}]\n").strip() or default
+    if user_input == '?':
+        print(f"Examples for {key}:")
+        first_example = example_rows[0]
+        last_example = example_rows[-1]
+        print(f"Example: {first_example[fields.index(key)]} ... {last_example[fields.index(key)]}")
+        user_input = input(f"{key} [{default}]\n").strip() or default
+
+    values[key] = user_input
+
+print("Break with Ctrl+C if incorrect:")
+print(values)
+input()  # Assume break with Ctrl+C if incorrect
+
+with open(file, 'a') as f:
+    writer = csv.DictWriter(f, fields)
+    writer.writerow(values)
+    print(f"Updated {file}")
+
+