forked from wcaleb/ricescheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
30 lines (27 loc) · 1.27 KB
/
cli.py
File metadata and controls
30 lines (27 loc) · 1.27 KB
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
import argparse
from ricescheduler import make_url, sorted_classes, schedule, output, date_formats
parser = argparse.ArgumentParser()
parser.add_argument('semester', help='Spring or Fall')
parser.add_argument('year', type=int, help='Year as YYYY')
parser.add_argument('days', help='String of class days as MTWRF')
parser.add_argument('--verbose', action='store_true', help='Show cancelled classes in output')
args = parser.parse_args()
def check_args():
checks = []
checks.append(set(args.days + 'MTWRF') != set('MTWRF'))
checks.append(args.semester.lower() not in ['spring','fall'])
if True in checks:
print 'Input error in your arguments.'
parser.print_help()
sys.exit(1)
if args.year < 2009:
print 'ERROR: The script only works for the years 2009 to the present.'
sys.exit(1)
check_args()
url = make_url(args.semester, str(args.year))
day_index = {'M': 'Monday', 'T': 'Tuesday', 'W': 'Wednesday', 'R': 'Thursday', 'F': 'Friday'}
weekdays = [day_index[d] for d in args.days]
possible_classes, no_classes = sorted_classes(weekdays, url)
course = schedule(possible_classes, no_classes, show_no=True)
print course
# ricescheduler.output_docx(schedule(possible_classes, no_classes, args.verbose), args.semester, str(args.year), 'output.docx')