-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhomework_generator.py
58 lines (46 loc) · 1.8 KB
/
homework_generator.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
from md_components import MD
from topics import Topic, TopicStore
import numpy as np
import argparse as ap
from gooey import Gooey, GooeyParser
@Gooey
def main():
ts = TopicStore()
topic_options = list(ts.topic_names.values)
parser = GooeyParser()
parser.add_argument('title', type=str, help='Title: Topic, Homework No., Due Date')
parser.add_argument('topic', type=str, help='Topic to generate questions for', choices=topic_options, nargs='+', widget='Dropdown')
parser.add_argument('--number', '-n', type=int, help='number of questions (default is 10)', default=10)
args = parser.parse_args()
args.topic = args.topic[0] # bug/quirk of the widget - returns a list always
try:
t = ts.make_Topic(args.topic)
except Exception as e:
print(args.topic)
print(e)
exit
print('Generating questions...')
questions, answers = [],[]
for i in range(args.number):
q,a = t.make_qa_pair()
questions.append(q+'\n')
answers.append(a)
print('making homework sheet...')
with open('Homework_{}.md'.format(args.title.replace(' ','_')), 'w') as f:
f.write(MD.to_title(args.title))
f.write('\n')
f.write(MD.to_subtitle(args.topic))
f.write('\n')
f.write("{}".format('\n\n'.join(questions)))
print('making solutions sheet...')
with open('Sols_{}.md'.format(args.title.replace(' ','_')), 'w') as f2:
f2.write(MD.to_title(args.title))
f2.write('\n')
f2.write(MD.to_subtitle(args.topic))
f2.write('\n\n')
if t.is_decimal:
f2.write("{}".format('\n'.join(['{:.1f}\n'.format(a) for a in answers])))
else:
f2.write("{}".format('\n'.join(['{}\n'.format(a) for a in answers])))
if __name__ == '__main__':
main()