Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
executable file
·57 lines (47 loc) · 1.67 KB
/
Copy pathcli.py
File metadata and controls
executable file
·57 lines (47 loc) · 1.67 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
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
#!python3
import json
import itertools as itt
import pandas as pd
from open_file import read_table
from make_ical import make_ical
from getpass import getpass
from sys import argv
from get_file import login, get_semester_list, get_courses
import argparse
if __name__ == '__main__':
# if __name__ == '__main__':
parser = argparse.ArgumentParser(description='transform course selection into ical')
parser.add_argument('--config', default=None)
args = parser.parse_args()
if args.config is not None:
configs = json.load(open(args.config))
else:
configs = dict()
try:
username = configs['username']
except KeyError as e:
username = input('username: ')
try:
password = configs['password']
except KeyError as e:
password = getpass('password (hidden): ')
driver = login(username, password)
for index, semester_name in zip(itt.count(0), get_semester_list(driver)):
print(index, ': ', '\t\t'.join(semester_name.split('\n')), end=';\n')
def get_semester_selection():
return list(map(int, input('enter desired semesters, seperated by space: ').split(' ')))
try:
semester_selection = configs['selection']
except KeyError as e:
semester_selection = get_semester_selection()
course_tables = get_courses(semester_selection, driver)
driver.close()
tables = [read_table(table) for table in course_tables]
courses = pd.concat(tables)
calendar = make_ical(courses )
try:
outfile_name = configs['outfile']
except KeyError as e:
outfile_name = input('outfile name: ')
with open(outfile_name, 'w') as fd:
fd.writelines(calendar)