-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathseed_dummy_db.py
More file actions
795 lines (749 loc) · 31.1 KB
/
Copy pathseed_dummy_db.py
File metadata and controls
795 lines (749 loc) · 31.1 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
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
import argparse
import os
from datetime import datetime, timedelta
from pathlib import Path
import sqlite3
def _now_iso() -> str:
return datetime.utcnow().isoformat(timespec="seconds")
def _table_columns(conn: sqlite3.Connection, table: str) -> set[str]:
return {r[1] for r in conn.execute(f"PRAGMA table_info({table})").fetchall()}
def _count(conn: sqlite3.Connection, table: str) -> int:
return int(conn.execute(f"SELECT COUNT(*) FROM {table}").fetchone()[0])
def _insert(conn: sqlite3.Connection, table: str, row: dict) -> None:
cols = _table_columns(conn, table)
payload = {k: v for k, v in row.items() if k in cols}
if not payload:
return
keys = list(payload.keys())
placeholders = ", ".join(["?"] * len(keys))
sql = f"INSERT OR IGNORE INTO {table} ({', '.join(keys)}) VALUES ({placeholders})"
conn.execute(sql, [payload[k] for k in keys])
def _ensure_rows(conn: sqlite3.Connection, table: str, rows: list[dict], min_rows: int = 4) -> None:
existing = _count(conn, table)
if existing >= min_rows:
return
needed = min_rows - existing
for row in rows[:needed]:
_insert(conn, table, row)
def _get_ids(conn: sqlite3.Connection, table: str) -> list[int]:
return [int(r[0]) for r in conn.execute(f"SELECT id FROM {table} ORDER BY id").fetchall()]
def _get_student_ids(conn: sqlite3.Connection) -> list[int]:
return [int(r[0]) for r in conn.execute("SELECT id FROM students ORDER BY id").fetchall()]
def seed(db_path: Path) -> None:
# Import the app and run init_db() so schema/migrations stay in sync.
import app as edu_app # type: ignore
edu_app.DB_PATH = db_path
edu_app.init_db()
conn = sqlite3.connect(db_path)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA foreign_keys = ON;")
try:
now = datetime.utcnow()
# schedule_groups: ensure at least 4 groups
_ensure_rows(
conn,
"schedule_groups",
[
{
"name": "Default Schedule",
"program": None,
"department": None,
"semester": None,
"created_at": _now_iso(),
},
{
"name": "B.Tech CSE - Sem 4 (Section A)",
"program": "B.Tech",
"department": "Computer Science",
"semester": 4,
"created_at": _now_iso(),
},
{
"name": "B.Tech CSE - Sem 4 (Section B)",
"program": "B.Tech",
"department": "Computer Science",
"semester": 4,
"created_at": _now_iso(),
},
{
"name": "BCA - Sem 2",
"program": "BCA",
"department": "Computer Applications",
"semester": 2,
"created_at": _now_iso(),
},
],
min_rows=4,
)
# Assign students across schedule groups (if schedule_id exists)
student_cols = _table_columns(conn, "students")
if "schedule_id" in student_cols:
conn.execute("UPDATE students SET schedule_id = 1 WHERE schedule_id IS NULL OR schedule_id = 0")
conn.execute("UPDATE students SET schedule_id = 2 WHERE id = 2")
conn.execute("UPDATE students SET schedule_id = 3 WHERE id = 3")
conn.execute("UPDATE students SET schedule_id = 4 WHERE id = 4")
# teachers
_ensure_rows(
conn,
"teachers",
[
{
"name": "Dr. A. Mehta",
"designation": "Associate Professor",
"department": "Computer Science",
"email": "amehta@institute.edu",
"phone": "9876543001",
"created_at": _now_iso(),
},
{
"name": "Prof. S. Sharma",
"designation": "Assistant Professor",
"department": "Computer Science",
"email": "ssharma@institute.edu",
"phone": "9876543002",
"created_at": _now_iso(),
},
{
"name": "Dr. R. Singh",
"designation": "Lab Incharge",
"department": "Physics",
"email": "rsingh@institute.edu",
"phone": "9876543003",
"created_at": _now_iso(),
},
{
"name": "Prof. M. Khan",
"designation": "Assistant Professor",
"department": "Computer Science",
"email": "mkhan@institute.edu",
"phone": "9876543004",
"created_at": _now_iso(),
},
],
)
# announcements
_ensure_rows(
conn,
"announcements",
[
{
"category": "URGENT",
"title": "Water supply maintenance",
"body": "Hostel water supply will be intermittent from 6AM–9AM tomorrow.",
"author": "Hostel Office",
"tag1": "#Hostel",
"tag2": "#Maintenance",
"created_at": _now_iso(),
},
{
"category": "GENERAL",
"title": "Library hours extended",
"body": "Reading hall open till 8PM this weekend.",
"author": "Library",
"tag1": "#Library",
"tag2": None,
"created_at": _now_iso(),
},
{
"category": "EVENT",
"title": "Coding contest",
"body": "Register for CodeSprint. Top 3 win goodies.",
"author": "Tech Club",
"tag1": "#Contest",
"tag2": "#Coding",
"created_at": _now_iso(),
},
{
"category": "EXAM",
"title": "Internal assessments",
"body": "Internal assessment schedule will be published on portal.",
"author": "Exam Cell",
"tag1": "#Exams",
"tag2": "#Notice",
"created_at": _now_iso(),
},
],
)
# news_posts
_ensure_rows(
conn,
"news_posts",
[
{
"priority": "URGENT",
"date_time": _now_iso(),
"heading": "Server maintenance tonight",
"body": "Portal services may be slow between 11PM–1AM.",
"sender": "IT Desk",
"news_type": "Alert",
"tags": "IT,Maintenance",
},
{
"priority": "HIGH",
"date_time": _now_iso(),
"heading": "Exam form deadline",
"body": "Exam form submission closes tomorrow 5PM.",
"sender": "Exam Cell",
"news_type": "Notice",
"tags": "Exams,Deadline",
},
{
"priority": "NORMAL",
"date_time": _now_iso(),
"heading": "New e-books added",
"body": "New DBMS and OS e-books are added to the library.",
"sender": "Library",
"news_type": "Update",
"tags": "Library,Books",
},
{
"priority": "LOW",
"date_time": _now_iso(),
"heading": "Canteen menu update",
"body": "New menu effective from next Monday.",
"sender": "Campus Services",
"news_type": "Update",
"tags": "Campus,Canteen",
},
],
)
# library_books
_ensure_rows(
conn,
"library_books",
[
{
"title": "Introduction to Algorithms",
"author": "Cormen",
"status": "Issued",
"due_date": (now + timedelta(days=7)).date().isoformat(),
},
{
"title": "Operating System Concepts",
"author": "Silberschatz",
"status": "Available",
"due_date": None,
},
{
"title": "Database System Concepts",
"author": "Korth",
"status": "Available",
"due_date": None,
},
{
"title": "Computer Networks",
"author": "Tanenbaum",
"status": "Issued",
"due_date": (now + timedelta(days=14)).date().isoformat(),
},
],
)
# library_resources
_ensure_rows(
conn,
"library_resources",
[
{
"heading": "DBMS Unit-2 Notes",
"description": "ER model and relational algebra summary.",
"pdf_url": "https://example.com/dbms-unit2.pdf",
"uploader": "Prof. Sharma",
"uploaded_at": _now_iso(),
"tags": "DBMS,SQL,Semester-4",
},
{
"heading": "OS Scheduling Cheatsheet",
"description": "FCFS, SJF, RR, Priority scheduling quick reference.",
"pdf_url": "https://example.com/os-scheduling.pdf",
"uploader": "Dr. Mehta",
"uploaded_at": _now_iso(),
"tags": "OS,CPU,Scheduling",
},
{
"heading": "CN Important Questions",
"description": "Transport layer and routing protocols.",
"pdf_url": "https://example.com/cn-impq.pdf",
"uploader": "Prof. Verma",
"uploaded_at": _now_iso(),
"tags": "CN,Networks,Semester-4",
},
{
"heading": "Discrete Math Practice Set",
"description": "Graphs, relations, and combinatorics.",
"pdf_url": "https://example.com/dm-practice.pdf",
"uploader": "Prof. Rao",
"uploaded_at": _now_iso(),
"tags": "DM,Math,Practice",
},
],
)
# exam_results
_ensure_rows(
conn,
"exam_results",
[
{
"course": "IT202",
"exam": "Mid Sem",
"score": 24,
"max_score": 30,
"grade": "A",
"published_at": _now_iso(),
},
{
"course": "IT203",
"exam": "Mid Sem",
"score": 26,
"max_score": 30,
"grade": "A+",
"published_at": _now_iso(),
},
{
"course": "IT204",
"exam": "Mid Sem",
"score": 22,
"max_score": 30,
"grade": "B+",
"published_at": _now_iso(),
},
{
"course": "ENV201",
"exam": "Assignment",
"score": 18,
"max_score": 20,
"grade": "A",
"published_at": _now_iso(),
},
],
)
# exam_forms (ensure 4)
_ensure_rows(
conn,
"exam_forms",
[
{
"title": "Examination Form",
"semester_label": "Odd Semester (2025-26)",
"status": "OPEN",
"open_from": (now - timedelta(days=5)).date().isoformat(),
"open_to": (now + timedelta(days=10)).date().isoformat(),
"fee": 1200,
"note": "Fill carefully.",
"apply_url": "https://forms.example.com/exam?roll={exam_roll_number}",
"apply_roll_placeholder": "{exam_roll_number}",
"program": "B.Tech",
"department": "Computer Science",
},
{
"title": "Back Paper Form",
"semester_label": "Odd Semester (2025-26)",
"status": "CLOSED",
"open_from": (now - timedelta(days=40)).date().isoformat(),
"open_to": (now - timedelta(days=30)).date().isoformat(),
"fee": 800,
"note": "Closed.",
"apply_url": "https://forms.example.com/backpaper?roll={exam_roll_number}",
"apply_roll_placeholder": "{exam_roll_number}",
},
{
"title": "Revaluation Form",
"semester_label": "Even Semester (2024-25)",
"status": "OPEN",
"open_from": (now - timedelta(days=1)).date().isoformat(),
"open_to": (now + timedelta(days=14)).date().isoformat(),
"fee": 500,
"note": "Upload supporting documents.",
"apply_url": "https://forms.example.com/reval?roll={exam_roll_number}",
"apply_roll_placeholder": "{exam_roll_number}",
},
{
"title": "Improvement Form",
"semester_label": "Even Semester (2024-25)",
"status": "CLOSED",
"open_from": (now - timedelta(days=60)).date().isoformat(),
"open_to": (now - timedelta(days=55)).date().isoformat(),
"fee": 700,
"note": "Contact exam cell for eligibility.",
},
],
min_rows=4,
)
# admit_card_openings
_ensure_rows(
conn,
"admit_card_openings",
[
{
"title": "Admit Card Download",
"semester_label": "Odd Semester (2025-26)",
"open_from": (now - timedelta(days=2)).date().isoformat(),
"open_to": (now + timedelta(days=20)).date().isoformat(),
"note": "Use your exam roll number.",
"program": "B.Tech",
"department": "Computer Science",
"admit_card_url": "https://admit.example.com/download?roll={exam_roll_number}",
"roll_placeholder": "{exam_roll_number}",
},
{
"title": "Admit Card Download",
"semester_label": "BCA Sem 2",
"open_from": (now - timedelta(days=5)).date().isoformat(),
"open_to": (now + timedelta(days=5)).date().isoformat(),
"note": "BCA students only.",
"program": "BCA",
"department": "Computer Applications",
"admit_card_url": "https://admit.example.com/bca?roll={exam_roll_number}",
"roll_placeholder": "{exam_roll_number}",
},
{
"title": "Admit Card Window (Closed)",
"semester_label": "Even Semester (2024-25)",
"open_from": (now - timedelta(days=30)).date().isoformat(),
"open_to": (now - timedelta(days=20)).date().isoformat(),
"note": "Closed.",
"admit_card_url": "https://admit.example.com/old?roll={exam_roll_number}",
"roll_placeholder": "{exam_roll_number}",
},
{
"title": "Special Admit Card",
"semester_label": "Odd Semester (2025-26)",
"open_from": (now - timedelta(days=1)).date().isoformat(),
"open_to": (now + timedelta(days=2)).date().isoformat(),
"note": "Special case window.",
"admit_card_url": "https://admit.example.com/special?roll={exam_roll_number}",
"roll_placeholder": "{exam_roll_number}",
},
],
)
# schedules (calendar events, legacy) - keep some rows anyway
_ensure_rows(
conn,
"schedules",
[
{
"title": "Seminar: AI in 2026",
"location": "Seminar Hall 1",
"start_at": (now + timedelta(days=2)).strftime("%Y-%m-%dT%H:%M"),
"end_at": (now + timedelta(days=2, hours=2)).strftime("%Y-%m-%dT%H:%M"),
"schedule_id": 2,
},
{
"title": "Sports Day",
"location": "Main Ground",
"start_at": (now + timedelta(days=7)).strftime("%Y-%m-%dT%H:%M"),
"end_at": (now + timedelta(days=7, hours=5)).strftime("%Y-%m-%dT%H:%M"),
"schedule_id": 1,
},
{
"title": "Placement Talk",
"location": "Auditorium",
"start_at": (now + timedelta(days=10)).strftime("%Y-%m-%dT%H:%M"),
"end_at": (now + timedelta(days=10, hours=1)).strftime("%Y-%m-%dT%H:%M"),
"schedule_id": 3,
},
{
"title": "Lab Maintenance",
"location": "Lab 2",
"start_at": (now + timedelta(days=1)).strftime("%Y-%m-%dT%H:%M"),
"end_at": (now + timedelta(days=1, hours=3)).strftime("%Y-%m-%dT%H:%M"),
"schedule_id": 4,
},
],
)
# weekly_timetable: add extra rows for multiple schedule groups
tt_cols = _table_columns(conn, "weekly_timetable")
if "schedule_id" in tt_cols:
base = [
(2, 0, "09:00", "10:00", "Data Structures", "C-101", "Dr. Mehta"),
(2, 1, "10:15", "11:15", "Operating Systems", "C-105", "Prof. Sharma"),
(2, 3, "11:30", "12:30", "Computer Networks", "C-110", "Prof. Verma"),
(2, 4, "09:00", "10:00", "Discrete Mathematics", "C-203", "Prof. Rao"),
(3, 0, "09:00", "10:00", "DSA (Batch B)", "C-102", "Dr. Mehta"),
(3, 2, "10:15", "11:15", "OS (Batch B)", "C-106", "Prof. Sharma"),
(3, 4, "11:30", "13:00", "Python Lab", "Lab-3", "TA Team"),
(3, 5, "09:00", "10:00", "Seminar", "Seminar Hall", "Prof. Khan"),
(4, 0, "09:00", "10:00", "C Programming", "BCA-201", "Prof. Anita"),
(4, 1, "10:15", "11:15", "Maths", "BCA-202", "Prof. Raj"),
(4, 3, "11:30", "12:30", "Digital Logic", "BCA-203", "Prof. Neeraj"),
(4, 4, "09:00", "10:00", "English", "BCA-204", "Prof. Sunita"),
]
for schedule_id, dow, st, et, subj, room, inst in base:
conn.execute(
"""
INSERT INTO weekly_timetable (schedule_id, day_of_week, start_time, end_time, subject, room, instructor)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(schedule_id, dow, st, et, subj, room, inst),
)
# programs
_ensure_rows(
conn,
"programs",
[
{"name": "B.Tech", "branch": "IT"},
{"name": "B.Tech", "branch": "CSE"},
{"name": "BCA", "branch": "General"},
{"name": "MBA", "branch": "HR"},
],
min_rows=4,
)
# subjects (schema varies across app versions; provide both key sets)
_ensure_rows(
conn,
"subjects",
[
{
"program_id": 1,
"semester": 4,
"code": "IT202",
"name": "Data Structure",
"course_code": "IT202",
"course_name": "Data Structure",
},
{
"program_id": 1,
"semester": 4,
"code": "IT203",
"name": "Python with Linux",
"course_code": "IT203",
"course_name": "Python with Linux",
},
{
"program_id": 1,
"semester": 4,
"code": "IT204",
"name": "Discrete Mathematics",
"course_code": "IT204",
"course_name": "Discrete Mathematics",
},
{
"program_id": 3,
"semester": 2,
"code": "BCA102",
"name": "C Programming",
"course_code": "BCA102",
"course_name": "C Programming",
},
],
min_rows=4,
)
# student_programs (map each student to a program)
student_ids = _get_student_ids(conn)
for sid in student_ids:
exists = conn.execute("SELECT 1 FROM student_programs WHERE student_id = ?", (int(sid),)).fetchone()
if exists is None:
prog = 1 if sid in (1, 2, 3, 4) else 1
_insert(conn, "student_programs", {"student_id": int(sid), "program_id": prog})
# student_subject_enrollments
subj_ids = [int(r[0]) for r in conn.execute("SELECT id FROM subjects ORDER BY id").fetchall()]
if subj_ids and _count(conn, "student_subject_enrollments") < 4:
session_label = "Odd Semester (2025-26)"
for sid in student_ids[:4]:
for sub in subj_ids[:3]:
try:
_insert(
conn,
"student_subject_enrollments",
{"student_id": int(sid), "subject_id": int(sub), "session_label": session_label},
)
except sqlite3.IntegrityError:
pass
# exam_sessions
_ensure_rows(
conn,
"exam_sessions",
[
{
"session_label": "Odd Semester (2025-26)",
"program_id": 1,
"semester": 4,
"university": "Demo University",
"college_label": "Demo College",
"exam_center": "Center 1",
"status": "ACTIVE",
"issued_at": _now_iso(),
},
{
"session_label": "Even Semester (2024-25)",
"program_id": 1,
"semester": 4,
"university": "Demo University",
"college_label": "Demo College",
"exam_center": "Center 2",
"status": "ACTIVE",
"issued_at": _now_iso(),
},
{
"session_label": "BCA Sem 2 (2025-26)",
"program_id": 3,
"semester": 2,
"university": "Demo University",
"college_label": "Demo College",
"exam_center": "Center 3",
"status": "ACTIVE",
"issued_at": _now_iso(),
},
{
"session_label": "MBA Sem 1 (2025-26)",
"program_id": 4,
"semester": 1,
"university": "Demo University",
"college_label": "Demo College",
"exam_center": "Center 4",
"status": "ACTIVE",
"issued_at": _now_iso(),
},
],
min_rows=4,
)
# exam_timetable
if _count(conn, "exam_timetable") < 4:
sess_id = int(conn.execute("SELECT id FROM exam_sessions ORDER BY id").fetchone()[0])
sub_id = int(conn.execute("SELECT id FROM subjects ORDER BY id").fetchone()[0])
_ensure_rows(
conn,
"exam_timetable",
[
{
"session_id": sess_id,
"subject_id": sub_id,
"paper_type": "REGULAR",
"exam_date": (now + timedelta(days=30)).date().isoformat(),
"exam_time": "11:30 AM to 01:00 PM",
},
{
"session_id": sess_id,
"subject_id": sub_id + 1,
"paper_type": "REGULAR",
"exam_date": (now + timedelta(days=31)).date().isoformat(),
"exam_time": "11:30 AM to 01:00 PM",
},
{
"session_id": sess_id,
"subject_id": sub_id + 2,
"paper_type": "REGULAR",
"exam_date": (now + timedelta(days=33)).date().isoformat(),
"exam_time": "11:30 AM to 01:00 PM",
},
{
"session_id": sess_id,
"subject_id": sub_id + 3,
"paper_type": "REGULAR",
"exam_date": (now + timedelta(days=35)).date().isoformat(),
"exam_time": "11:30 AM to 01:00 PM",
},
],
min_rows=4,
)
# exam_form_submissions (link students to first exam form)
if _count(conn, "exam_form_submissions") < 4:
form_id = int(conn.execute("SELECT id FROM exam_forms ORDER BY id").fetchone()[0])
for sid in student_ids[:4]:
student = conn.execute("SELECT * FROM students WHERE id = ?", (int(sid),)).fetchone()
if not student:
continue
try:
_insert(
conn,
"exam_form_submissions",
{
"form_id": form_id,
"student_id": int(sid),
"submitted_at": _now_iso(),
"student_name": student["name"],
"roll_no": student["roll_no"],
"program": student["program"],
"semester": int(student["sem"]),
"phone": student["phone"],
"email": student["email"],
"guardian": student["guardian"],
"address": "Demo Address",
"category": "GENERAL",
"gender": "Male",
"status": "Active",
"residential_status": student["residential_status"],
},
)
except sqlite3.IntegrityError:
pass
# admit_cards + subjects
if _count(conn, "admit_cards") < 4:
for sid in student_ids[:4]:
student = conn.execute("SELECT * FROM students WHERE id = ?", (int(sid),)).fetchone()
details = conn.execute("SELECT * FROM student_details WHERE student_id = ?", (int(sid),)).fetchone()
father = (details["father_name"] if details else "Father")
gender = (details["gender"] if details else "Male")
category = (details["category"] if details else "GENERAL")
address = (details["address"] if details else "Demo Address")
conn.execute(
"""
INSERT INTO admit_cards (
student_id, university, session_label, program_label, college_label,
student_name, roll_number, father_name, gender, category, address,
exam_center, image_label, issued_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
int(sid),
"Demo University",
"Odd Semester (2025-26)",
"Program",
"Demo College",
student["name"],
student["roll_no"],
father,
gender,
category,
address,
"Center 1",
None,
_now_iso(),
),
)
admit_id = int(conn.execute("SELECT last_insert_rowid()").fetchone()[0])
# add 3 subjects per admit card
for i in range(1, 4):
_insert(
conn,
"admit_card_subjects",
{
"admit_card_id": admit_id,
"sno": i,
"paper_type": "REGULAR",
"subject_code": f"SUB{i:03d}",
"subject_name": f"Subject {i}",
"exam_date": (now + timedelta(days=25 + i)).date().isoformat(),
"exam_time": "11:30 AM to 01:00 PM",
},
)
conn.commit()
finally:
conn.close()
def main() -> int:
parser = argparse.ArgumentParser(description="Generate a fresh dummy eduportal.db with seed data")
parser.add_argument(
"--db",
default=str(Path(__file__).with_name("eduportal.db")),
help="Path to sqlite db file (default: ./eduportal.db)",
)
parser.add_argument(
"--force",
action="store_true",
help="Overwrite existing db file if it exists",
)
args = parser.parse_args()
db_path = Path(args.db).resolve()
if db_path.exists():
if not args.force:
raise SystemExit(
f"DB already exists at {db_path}. Re-run with --force to overwrite."
)
os.remove(db_path)
seed(db_path)
print(f"Dummy database created at: {db_path}")
print("Login credentials:")
print("- Admin: admin / admin123")
print("- Students: use one of the seeded roll numbers with password student123")
return 0
if __name__ == "__main__":
raise SystemExit(main())