-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
187 lines (155 loc) · 10.6 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import json
def batch_extractor(text):
start_bracket = text.find('(')
if start_bracket != -1:
return text[1:start_bracket].strip()
return ""
def subject_extractor(text):
start_bracket = text.find('(')
if start_bracket != -1:
end_bracket = text.find(')', start_bracket)
if end_bracket != -1:
return text[start_bracket + 1:end_bracket]
return ""
def location_extractor(text):
start_dash = text.find('-')
if start_dash != -1:
end_slash = text.find('/', start_dash)
if end_slash != -1:
return text[start_dash + 1:end_slash]
return ""
def subject_name_extractor(subjects_dict, code):
for i in range(len(subjects_dict["Code"])):
if subjects_dict["Code"][i] == code:
return subjects_dict["Subject"][i]
return ""
def time_table_creator(time_table_json_string, subject_json_string):
time_table = json.loads(time_table_json_string)
subject = subject_json_string
your_time_table = []
batch = input("Enter your Batch: ").upper().strip()
electives_subject_codes = []
n = int(input("Number of electives you have: "))
for i in range(n):
electives_subject_codes.append(input("Enter the subject code of the elective (shortttened one): ").upper().strip())
for day, it in time_table.items():
for time, classes in it.items():
for indi_class in classes:
subjectCode = indi_class.strip()
code = subject_extractor(subjectCode)
if batch in batch_extractor(indi_class.strip()) and "-" not in batch_extractor(indi_class.strip()):
if len(indi_class.strip()) > 0:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
for elective_code in electives_subject_codes:
if len(indi_class)>0 and indi_class[0] != "P":
if subject_extractor(indi_class) == elective_code:
extracted_batch = batch_extractor(indi_class)
if ("-" not in extracted_batch) or ("," not in extracted_batch):
if len(extracted_batch) in [0,3]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
elif len(extracted_batch) == 1:
if extracted_batch == batch[0]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
elif len(extracted_batch) == 2:
for letter in extracted_batch:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
if ("," in extracted_batch):
batch_list = extracted_batch.split(",")
for index, b in enumerate(batch_list):
if len(batch_list) > 3:
if b.strip()[0].isalpha():
if b.strip()[0] == batch[0]:
batch_list[index] = b[1:]
if batch_list[index] == batch[1:]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
break
else:
if b == batch[1:]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
if b.strip()[0] == batch[0]:
if len(b.strip()) == 1:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
batch_nums = ((b.strip())).split("-")
if len(batch) > 1 and all(len(num.strip()) > 1 for num in batch_nums):
batch_number_str = batch.strip()[1:]
if batch_number_str:
batch_number = int(batch_number_str)
batch_num_0 = int(batch_nums[0].strip()[1:])
batch_num_1 = int(batch_nums[1].strip()[1:])
if batch_num_0 <= batch_number <= batch_num_1:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
print("Batch string is empty or incorrectly sliced.")
else:
print("Batch string or batch_nums are incorrectly formatted.")
string_time_table = json.dumps(your_time_table)
return string_time_table
with open("./data/json/time_table.json", 'r') as file:
time_table = json.load(file)
with open("./data/json/subject.json", 'r') as file:
subject = json.load(file)
your_time_table = []
batch = input("Enter your Batch: ").upper().strip()
electives_subject_codes = []
n = int(input("Number of electives you have: "))
for i in range(n):
electives_subject_codes.append(input("Enter the subject code of the elective (shortttened one): ").upper().strip())
for day, it in time_table.items():
for time, classes in it.items():
for indi_class in classes:
subjectCode = indi_class.strip()
code = subject_extractor(subjectCode)
if batch in batch_extractor(indi_class.strip()) and "-" not in batch_extractor(indi_class.strip()):
if len(indi_class.strip()) > 0:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
for elective_code in electives_subject_codes:
if len(indi_class)>0 and indi_class[0] != "P":
if subject_extractor(indi_class) == elective_code:
extracted_batch = batch_extractor(indi_class)
if ("-" not in extracted_batch) or ("," not in extracted_batch):
if len(extracted_batch) in [0,3]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
elif len(extracted_batch) == 1:
if extracted_batch == batch[0]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
elif len(extracted_batch) == 2:
for letter in extracted_batch:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
if ("," in extracted_batch):
batch_list = extracted_batch.split(",")
for index, b in enumerate(batch_list):
if len(batch_list) > 3:
if b.strip()[0].isalpha():
if b.strip()[0] == batch[0]:
batch_list[index] = b[1:]
if batch_list[index] == batch[1:]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
break
else:
if b == batch[1:]:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
if b.strip()[0] == batch[0]:
if len(b.strip()) == 1:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
batch_nums = ((b.strip())).split("-")
if len(batch) > 1 and all(len(num.strip()) > 1 for num in batch_nums):
batch_number_str = batch.strip()[1:]
if batch_number_str:
batch_number = int(batch_number_str)
batch_num_0 = int(batch_nums[0].strip()[1:])
batch_num_1 = int(batch_nums[1].strip()[1:])
if batch_num_0 <= batch_number <= batch_num_1:
your_time_table.append([day, time, subject_name_extractor(subject, code), indi_class.strip()[0], location_extractor(subjectCode)])
else:
print("Batch string is empty or incorrectly sliced.")
else:
print("Batch string or batch_nums are incorrectly formatted.")
print()
for t in your_time_table:
print(t)