-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
130 lines (114 loc) · 4.14 KB
/
main.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from pprint import pprint
from repository import Repository
from controller import Controller
from validation import check_day, check_subgroup
import sys
import getopt
import datetime as dt
def main(argv):
help_info = '''
This is a script to show the university schedule for the
students at Babes Bolyai University majoring in Computer Science
in german.
Help:
Use -h(--help) options to see how the scripdayt works
Use -t(--today) to see the schedule for today
Use -g(--group) to see the schedule for a specific group
Use -d(--day) to see the schedule for a specific day
Accepted values are:
Monday/Luni
Tuesday/Marti
Wendsday/Miercuri
Thursday/Joi
Friday/Vineri
Possible options combinations:
- group and today
- group and day
'''
correct = False
try:
opts, args = getopt.getopt(
argv, 'thg:d:', ['help', 'today', 'group=', 'day='])
except getopt.GetoptError:
print(help_info)
sys.exit(2)
day = None
group = None
today = False
today_day = None
help = False
for opt, arg in opts:
if opt in ('-h', '--help'):
print(help_info)
help = True
elif opt in ('-t', '--today'):
today = True
today_day = dt.datetime.today().weekday()
elif opt in ('-d', '--day'):
day = arg
elif opt in ('-g', '--group'):
group = arg
if help is False:
while not correct:
try:
print('\n')
year = int(input('Enter your current university year: '))
semester = int(input('Enter your current semester: '))
correct = True
print('\nLoading data...')
except ValueError:
print('Given values are not correct. Please enter them again.')
sys.exit(2)
r = Repository(semester, year)
ctrl = Controller(r)
print('\nDone.')
if day is None and group is None and today is False:
print('\n')
ctrl.get_all()
elif day is None and group is not None and today is True:
print('\n')
if len(group) == 3:
try:
subgroup = check_subgroup(int(input('Enter subgroup: ')))
print('\n')
print(f'{group}/{subgroup}')
ctrl.get_by_group_and_day(
day=check_day(today_day), group=f'{group}/{subgroup}')
except ValueError:
print('Given values are not correct. Please rerun the script.')
else:
ctrl.get_by_group_and_day(
day=check_day(today_day), group=group)
elif day is not None and group is not None and today is False:
print('\n')
if len(group) == 3:
try:
subgroup = check_subgroup(int(input('Enter subgroup: ')))
print('\n')
ctrl.get_by_group_and_day(day=check_day(
day), group=f'{group}/{subgroup}')
except ValueError:
print('Given values are not correct. Please rerun the script.')
else:
ctrl.get_by_group_and_day(day=check_day(day), group=group)
elif day is not None:
print('\n')
ctrl.get_by_day(check_day(day))
elif today is True:
print('here\n')
ctrl.get_by_day(check_day(today_day))
elif group is not None:
print('\n')
if len(group) == 3:
try:
subgroup = check_subgroup(int(input('Enter subgroup: ')))
print('\n')
ctrl.get_by_group(f'{group}/{subgroup}')
except ValueError:
print('Given values are not correct. Please rerun the script.')
else:
ctrl.get_by_group(group)
else:
print('No such combination of arguments possible.')
if __name__ == "__main__":
main(sys.argv[1:])