-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomposer.py
executable file
·113 lines (91 loc) · 3.05 KB
/
composer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
import csv
import sys, getopt
import random
import os
elements_path = './sample_inputs/elements.csv' #where are input elements for the todo lists
quotes_path = './sample_inputs/quotes.csv' #where are input quotes for the todo lists
write_path_default_value = './todays_routine.org' #where to write the output, if it's not specified in an env variable
write_path = os.getenv('LIZTOMANIA_WRITE_PATH',write_path_default_value)
#assuming need ** prefix to paste into bigger file right now
def emacsify(rows,star_prefix = 2):
output_text = ''
categories = ["1. morning", "2. afternoon", "3. evening"]
for category in categories:
for i in range(star_prefix):
output_text += "*"
output_text += f" {category}\n"
for row in rows:
if row["timing"] == category:
for i in range(star_prefix+1):
output_text += "*"
output_text += f' {row["name"]}\n'
if row["detail"] != '':
output_text += f'{row["detail"]}\n'
return output_text
def parse_cli(argv):
help_string = './composer.py\n-p <priority: ["red"|"yellow"|"green"]>\n-d <daytype: ["workday"|"weekend"]>'
arguments = {}
try:
opts, args = getopt.getopt(argv,'hp:d:',['priority=','day_type='])
except getopt.GetoptError:
print(help_string)
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(help_string)
sys.exit()
elif opt in ("-p", "--priority"):
arguments["priority"] = arg
elif opt in ("-d", "--daytype"):
arguments["day_type"] = arg
return arguments
#return T or F
#lets things through unless reason to remove
def row_test(row, arguments):
debug = False
if debug:
print(f'row: {row}')
print(f'args: {arguments}')
#don't show work stuff on weekends
if "day_type" in arguments and arguments["day_type"] == "weekend":
if row["category"] == "work":
return False
#don't show non-urgent stuff on stressful days
if "priority" in arguments:
if arguments["priority"] == "red" and (row["priority"] in ["green", "yellow"]):
return False
elif arguments["priority"] == "yellow" and (row["priority"] == "green"):
return False
return True
def main(argv):
arguments = parse_cli(argv)
debug = False
formatted_output = ''
csv_reader = ''
quote_rows = []
with open(quotes_path) as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
for row in csv_reader:
quote_rows.append(row)
quote_count = len(quote_rows)
selections = 2
# can currently select the same quote multiple times/day
for i in range(0,selections):
selection_index = random.randint(0,quote_count-1)
quote_row = quote_rows[selection_index]
formatted_output += f'"{quote_row["Quote"]}" -{quote_row["Attribution"]}\n'
csv_reader = ''
action_rows_selected = []
with open(elements_path) as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
for row in csv_reader:
if row_test(row, arguments):
action_rows_selected.append(row)
formatted_output += emacsify(action_rows_selected)
if debug:
print(formatted_output)
with open(write_path, 'w') as file:
file.write(formatted_output)
# needed to actually run the program
main(sys.argv[1:])