X-Git-Url: https://apps.delaporte.us/gitweb/dotfiles.git/blobdiff_plain/e607671cc5f8992240864b233a4a9cc4353f2909..HEAD:/bin/clerk diff --git a/bin/clerk b/bin/clerk index e4f7a19..7c7b504 100755 --- a/bin/clerk +++ b/bin/clerk @@ -1,12 +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) @@ -14,29 +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 - example = next(reader) + for i in range(4): + example_rows.append(next(reader)) + +DATE_FORMAT = '%Y-%m-%d' + +def today(): + return dt.now().strftime(DATE_FORMAT) -print(example) - values = {} for key in fields: - print(key) - values[key] = input() + 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) -if input() == 'y': - with open(file, 'a') as f: - writer = csv.DictWriter(f, fields) - writer.writerow(values) - print(f"Updated {file}") +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}")