-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheup.py
497 lines (460 loc) · 18.8 KB
/
eup.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
import os
def create_question_papers(username):
choice = input("Do you want to create new question paper(y/n)?").lower()
if choice == "y":
question_set = input("Set A(a) or Set B(b)?(a/b/q)").lower()
if question_set == "a":
file_name = f"set_{question_set}.txt"
elif question_set == "b":
file_name = f"set_{question_set}.txt"
elif question_set == "q":
print("Exiting...")
return False
else:
print("Invalid choice. Please try again.")
return False
if os.path.exists(file_name):
override = input(
f"{file_name} already exists. Do you want to override it? (yes/no): "
)
if override.lower() != "yes":
print("Question paper not created.")
return False
with open(f"sets/{file_name}", "w") as f:
f.write(f"{file_name}")
print(f"{file_name} created successfully.")
else:
print("Exiting...")
os.system("sleep 3")
os.system("clear")
return True
def add_questions_to_exam_papers(username):
# Define file paths
topics_file = "texts/topics.txt"
questions_file = "texts/questions.txt"
set_a_file = f"sets/set_a.txt"
set_b_file = f"sets/set_b.txt"
# Read topics from file
topics = {}
with open(topics_file, "r") as f:
for line in f:
topic, subject = line.strip().split("@")
topics[subject] = topics.get(subject, [])
topics[subject].append(topic)
# Read questions from file
questions = {}
with open(questions_file, "r") as f:
for line in f:
parts = line.strip().split(", ")
topic_subject = parts[0]
section = parts[1]
question = parts[2]
if section == "Section_A":
answer = parts[3]
options = parts[4:]
questions[topic_subject] = questions.get(topic_subject, {})
questions[topic_subject][section] = questions[topic_subject].get(
section, []
)
questions[topic_subject][section].append((question, answer, options))
else:
questions[topic_subject] = questions.get(topic_subject, {})
questions[topic_subject][section] = questions[topic_subject].get(
section, []
)
questions[topic_subject][section].append((question,))
# Get user input for set choice
print("Choose a set:")
print("1. Set A")
print("2. Set B")
set_choice = input("Enter set number: ")
if set_choice == "1":
set_file = set_a_file
elif set_choice == "2":
set_file = set_b_file
else:
print("Invalid set choice. Please enter 1 or 2.")
return False
# Display subjects for user to choose
print("Choose a subject:")
for i, subject in enumerate(topics.keys()):
print(f"{i+1}. {subject}")
subject_choice = int(input("Enter subject number: "))
subject = list(topics.keys())[subject_choice - 1]
# Display topics for user to choose
print("Choose a topic:")
for i, topic in enumerate(topics[subject]):
print(f"{i+1}. {topic}")
topic_choice = int(input("Enter topic number: "))
topic = topics[subject][topic_choice - 1]
topic_subject = f"{topic}@{subject}"
# Display Section A questions for user to choose
if "Section_A" in questions[topic_subject]:
print("Choose Section A questions:")
for i, question in enumerate(questions[topic_subject]["Section_A"]):
print(f"{i+1}. {question[0]}")
for j, option in enumerate(question[2]):
print(f" {j+1}. {option}")
section_a_questions = []
while len(section_a_questions) < 5:
question_choice = input("Enter question number (or 'done' to finish): ")
if question_choice.lower() == "done":
break
try:
question_choice = int(question_choice)
for i, question in enumerate(questions[topic_subject]["Section_A"]):
if i + 1 == question_choice:
section_a_questions.append(
(
topic_subject,
"Section_A",
question[0],
question[2],
)
)
break
except ValueError:
print("Invalid input. Please enter a number or 'done'.")
else:
print("No Section A questions available for this topic.")
section_a_questions = []
# Display Section B questions for user to choose
if "Section_B" in questions[topic_subject]:
print("Choose Section B questions:")
for i, question in enumerate(questions[topic_subject]["Section_B"]):
print(f"{i+1}. {question[0]}")
section_b_questions = []
while len(section_b_questions) < 3:
question_choice = input("Enter question number (or 'done' to finish): ")
if question_choice.lower() == "done":
break
try:
question_choice = int(question_choice)
for i, question in enumerate(questions[topic_subject]["Section_B"]):
if i + 1 == question_choice:
section_b_questions.append(
(topic_subject, "Section_B", question[0])
)
break
except ValueError:
print("Invalid input. Please enter a number or 'done'.")
else:
print("No Section B questions available for this topic.")
section_b_questions = []
# Write chosen questions to set file
with open(set_file, "w") as f:
for question in section_a_questions:
f.write(
f"{question[0]}, {question[1]}, {question[2]}, {', '.join(question[3])}\n"
)
for question in section_b_questions:
f.write(f"{question[0]}, {question[1]}, {question[2]}\n")
print("... Adding questions ...")
os.system("sleep 3")
os.system("clear")
return True
def edit_question_papers(username):
# Define file paths
questions_file = "texts/questions.txt"
set_a_file = "sets/set_a.txt"
set_b_file = "sets/set_b.txt"
# Read questions from file
questions = {}
with open(questions_file, "r") as f:
for line in f:
parts = line.strip().split(", ")
if len(parts) < 3:
print(f"Skipping line: {line} (not enough values)")
continue
topic_subject = parts[0]
section = parts[1]
if len(parts) > 2:
question = parts[2]
else:
question = ""
if section == "Section_A":
if len(parts) > 3:
answer = parts[3]
else:
answer = ""
if len(parts) > 4:
options = parts[4:]
else:
options = []
questions[topic_subject] = questions.get(topic_subject, {})
questions[topic_subject][section] = questions[topic_subject].get(
section, []
)
questions[topic_subject][section].append((question, answer, options))
else:
questions[topic_subject] = questions.get(topic_subject, {})
questions[topic_subject][section] = questions[topic_subject].get(
section, []
)
questions[topic_subject][section].append((question,))
# Get user input for set choice
print("Choose a set:")
print("1. Set A")
print("2. Set B")
set_choice = input("Enter set number: ")
if set_choice == "1":
set_file = set_a_file
elif set_choice == "2":
set_file = set_b_file
else:
print("Invalid set choice. Please enter 1 or 2.")
return False
# Read existing questions from set file
existing_questions = {}
with open(set_file, "r") as f:
for line in f:
parts = line.strip().split(", ")
if len(parts) < 3:
print(f"Skipping line: {line} (not enough values)")
continue
topic_subject = parts[0]
section = parts[1]
if len(parts) > 2:
question = parts[2]
else:
question = ""
existing_questions[topic_subject] = existing_questions.get(
topic_subject, {}
)
existing_questions[topic_subject][section] = existing_questions[
topic_subject
].get(section, [])
if section == "Section_A":
if len(parts) > 3:
options = parts[3:]
else:
options = []
existing_questions[topic_subject][section].append((question, options))
else:
existing_questions[topic_subject][section].append((question,))
# Replace Section A questions
print("Replace Section A questions:")
topic_subject = "physics@science"
section = "Section_A"
if (
topic_subject in existing_questions
and section in existing_questions[topic_subject]
):
for i, question in enumerate(existing_questions[topic_subject][section]):
print(f"{i+1}. {question[0]}")
section_a_questions_to_replace = input(
"Enter question numbers to replace (comma-separated): "
).split(", ")
for question_number in section_a_questions_to_replace:
question_number = int(question_number)
if question_number > 0 and question_number <= len(
existing_questions[topic_subject][section]
):
question = existing_questions[topic_subject][section][
question_number - 1
][0]
print("Choose a new question:")
for i, new_question in enumerate(questions[topic_subject][section]):
print(f"{i+1}. {new_question[0]} (Answer: {new_question[1]})")
for j, option in enumerate(new_question[2]):
print(f" {j+1}. {option}")
new_question_choice = int(input("Enter new question number: "))
new_question = questions[topic_subject][section][
new_question_choice - 1
]
existing_questions[topic_subject][section][question_number - 1] = (
new_question[0],
new_question[2],
)
else:
print(f"Invalid question number: {question_number}")
else:
print("No questions found in Section A")
# Replace Section B questions
print("Replace Section B questions:")
topic_subject = "physics@science"
section = "Section_B"
if (
topic_subject in existing_questions
and section in existing_questions[topic_subject]
):
for i, question in enumerate(existing_questions[topic_subject][section]):
print(f"{i+1}. {question[0]}")
section_b_questions_to_replace = input(
"Enter question numbers to replace (comma-separated): "
).split(", ")
for question_number in section_b_questions_to_replace:
question_number = int(question_number)
if question_number > 0 and question_number <= len(
existing_questions[topic_subject][section]
):
question = existing_questions[topic_subject][section][
question_number - 1
][0]
print("Choose a new question:")
for i, new_question in enumerate(questions[topic_subject][section]):
print(f"{i+1}. {new_question[0]}")
new_question_choice = int(input("Enter new question number: "))
new_question = questions[topic_subject][section][
new_question_choice - 1
]
existing_questions[topic_subject][section][question_number - 1] = (
new_question[0],
)
else:
print(f"Invalid question number: {question_number}")
else:
print("No questions found in Section B")
# Write replaced questions back to set file
with open(set_file, "w") as f:
for topic_subject, sections in existing_questions.items():
for section, questions in sections.items():
for question in questions:
if section == "Section_A":
f.write(
f"{topic_subject}, {section}, {question[0]}, {', '.join(question[1])}\n"
)
else:
f.write(f"{topic_subject}, {section}, {question[0]}\n")
print("... Editing questions! ...")
os.system("sleep 3")
os.system("clear")
return True
def view_question_papers(username):
# Get list of available sets
import os
sets_dir = "sets/"
sets = [
f for f in os.listdir(sets_dir) if f.startswith("set") and f.endswith(".txt")
]
# Display available sets and ask user to choose one
print("Available sets:")
for i, set_file in enumerate(sets, 1):
print(f"{i}. {set_file}")
while True:
choice = input("Enter the number of the set you want to view: ")
if choice.isdigit() and 1 <= int(choice) <= len(sets):
set_file = sets[int(choice) - 1]
break
else:
print("Invalid choice. Please try again.")
# Read existing questions from set file
existing_questions = {}
set_file_path = os.path.join(
sets_dir, set_file
) # Join the directory path with the file name
with open(set_file_path, "r") as f:
for line in f:
parts = line.strip().split(", ")
if len(parts) < 3:
print(f"Skipping line: {line} (not enough values)")
continue
topic_subject = parts[0]
section = parts[1]
if len(parts) > 2:
question = parts[2]
else:
question = ""
if section == "Section_A":
if len(parts) > 3:
options = parts[3:]
else:
options = []
existing_questions[topic_subject] = existing_questions.get(
topic_subject, {}
)
existing_questions[topic_subject][section] = existing_questions[
topic_subject
].get(section, [])
existing_questions[topic_subject][section].append((question, options))
else:
existing_questions[topic_subject] = existing_questions.get(
topic_subject, {}
)
existing_questions[topic_subject][section] = existing_questions[
topic_subject
].get(section, [])
existing_questions[topic_subject][section].append((question,))
# Display question paper
print("... Displaying questions ...")
os.system("sleep 3")
os.system("clear")
print("\nQuestion Paper: ")
print("")
print("")
print(f"{set_file.split('.')[0]}")
print("")
for topic_subject, sections in existing_questions.items():
for section, questions in sections.items():
if section == "Section_A":
print(f"{section}:")
for i, (question, options) in enumerate(questions, 1):
print(f"Q{i}. {question}")
# Display options
for j, option in enumerate(options, 97):
print(f"{chr(j)}. {option}")
elif section == "Section_B":
print(f"\n{section}:")
for i, (question,) in enumerate(questions, 6):
print(f"Q{i}. {question}")
print("")
print("")
print("")
print(".............................................................................")
a = input("Press any key to exit")
return True
# def export_question_paper(username, set_file):
# # Read existing questions from set file
# existing_questions = {}
# sets_dir = "sets/"
# set_file_path = os.path.join(sets_dir, set_file)
# with open(set_file_path, "r") as f:
# for line in f:
# parts = line.strip().split(", ")
# if len(parts) < 3:
# print(f"Skipping line: {line} (not enough values)")
# continue
# topic_subject = parts[0]
# section = parts[1]
# if len(parts) > 2:
# question = parts[2]
# else:
# question = ""
# if section == "Section_A":
# if len(parts) > 3:
# options = parts[3:]
# else:
# options = []
# existing_questions[topic_subject] = existing_questions.get(
# topic_subject, {}
# )
# existing_questions[topic_subject][section] = existing_questions[
# topic_subject
# ].get(section, [])
# existing_questions[topic_subject][section].append((question, options))
# else:
# existing_questions[topic_subject] = existing_questions.get(
# topic_subject, {}
# )
# existing_questions[topic_subject][section] = existing_questions[
# topic_subject
# ].get(section, [])
# existing_questions[topic_subject][section].append((question,))
# # Export to text file
# export_file = f"{set_file.split('.')[0]}.txt"
# with open(export_file, "w") as f:
# for topic_subject, sections in existing_questions.items():
# for section, questions in sections.items():
# if section == "Section_A":
# f.write(f"{section}:\n")
# for i, (question, options) in enumerate(questions, 1):
# f.write(f"Q{i}. {question}\n")
# for j, option in enumerate(options, 97):
# f.write(f"{chr(j)}. {option}\n")
# f.write("\n")
# elif section == "Section_B":
# f.write(f"\n{section}:\n")
# for i, (question,) in enumerate(questions, 6):
# f.write(f"Q{i}. {question}\n")
# f.write("\n")
# print(f"Set exported to {export_file}")