]> apps.delaporte.us Git - minion.git/commitdiff
Add clerk command for quick CSV data collection
authorEdward <delaport@illinois.edu>
Thu, 13 Aug 2026 21:03:28 +0000 (16:03 -0500)
committerEdward <delaport@illinois.edu>
Thu, 13 Aug 2026 21:03:28 +0000 (16:03 -0500)
bin/clerk [new file with mode: 0755]

diff --git a/bin/clerk b/bin/clerk
new file mode 100755 (executable)
index 0000000..7c7b504
--- /dev/null
+++ b/bin/clerk
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+
+import csv
+from datetime import datetime as dt
+import os
+
+DATA_DIR=os.path.expanduser('~/Journal/2026/Data')
+
+data_files = {}
+for root, _, files in os.walk(DATA_DIR):
+    for file in files:
+        name, ext = os.path.splitext(file)
+        if ext == '.csv':
+            data_files[name] = os.path.join(root, file)
+
+print(data_files.keys())
+for idx, file in enumerate(data_files.keys()):
+    print(f"{idx} - {file}")
+
+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}")
+
+