]> apps.delaporte.us Git - minion.git/blob - bin/clerk
README update
[minion.git] / bin / clerk
1 #!/usr/bin/python
2
3 import csv
4 from datetime import datetime as dt
5 import os
6
7 DATA_DIR=os.path.expanduser('~/Journal/2026/Data')
8
9 data_files = {}
10 for root, _, files in os.walk(DATA_DIR):
11 for file in files:
12 name, ext = os.path.splitext(file)
13 if ext == '.csv':
14 data_files[name] = os.path.join(root, file)
15
16 print(data_files.keys())
17 for idx, file in enumerate(data_files.keys()):
18 print(f"{idx} - {file}")
19
20 user_input = input(f"Select a file:\n").strip() or default
21 key = list(data_files.keys())[int(user_input)]
22
23 file = data_files[key]
24
25 print(file)
26
27 example_rows = []
28
29 with open(file, 'r') as f:
30 reader = csv.reader(f, delimiter=',', quotechar='"')
31 fields = next(reader) # require header row
32 for i in range(4):
33 example_rows.append(next(reader))
34
35 DATE_FORMAT = '%Y-%m-%d'
36
37 def today():
38 return dt.now().strftime(DATE_FORMAT)
39
40 values = {}
41 for key in fields:
42 default = ''
43 if key == 'date':
44 default = today()
45 user_input = input(f"{key} [{default}]\n").strip() or default
46 if user_input == '?':
47 print(f"Examples for {key}:")
48 first_example = example_rows[0]
49 last_example = example_rows[-1]
50 print(f"Example: {first_example[fields.index(key)]} ... {last_example[fields.index(key)]}")
51 user_input = input(f"{key} [{default}]\n").strip() or default
52
53 values[key] = user_input
54
55 print("Break with Ctrl+C if incorrect:")
56 print(values)
57 input() # Assume break with Ctrl+C if incorrect
58
59 with open(file, 'a') as f:
60 writer = csv.DictWriter(f, fields)
61 writer.writerow(values)
62 print(f"Updated {file}")
63
64