@@ -27,17 +27,38 @@ python setup.py install
27
27
``` python
28
28
import usf
29
29
30
- data = usf.read(" schedule.usf" )
31
- if usf.is_valid(data):
32
- print (" Valid USF file" )
33
- subjects = usf.get_subjects(data)
34
- print (subjects)
30
+ # Initialize the USF Parser with the file path
31
+ parser = usf.USFParser(" schedule.usf" )
32
+
33
+ # Get subjects from the parsed data
34
+ subjects = parser.get_subjects()
35
+ print (subjects)
36
+
37
+ # Get periods
38
+ periods = parser.get_periods()
39
+ print (periods)
40
+
41
+ # Get the timetable
42
+ timetable = parser.get_timetable()
43
+ print (timetable)
44
+ ```
45
+
46
+ ### Validating a USF file
47
+ ``` python
48
+ import usf
49
+
50
+ # Initialize the USF Validator with a schema file
51
+ validator = usf.USFValidator(" schema.json" )
52
+
53
+ # Validate the parsed data
54
+ if validator.validate(data):
55
+ print (" Valid USF data" )
35
56
else :
36
- print (" Invalid USF file " )
57
+ print (" Invalid USF data " )
37
58
```
38
59
39
60
### Creating a USF file
40
- ``` python
61
+ ··· python
41
62
import usf
42
63
43
64
# Initialize the USF Generator (version 1 by default)
@@ -57,31 +78,45 @@ usf_generator.add_schedule(day=2, week_type="odd", subject="Physics", period_ind
57
78
58
79
# Generate the USF data and save it to a file
59
80
usf_generator.save_to_file("schedule.usf")
60
- ```
81
+ ···
61
82
62
83
### Adding a Course to an Existing USF File
63
84
``` python
85
+ import usf
86
+
87
+ # Initialize the USF Parser
64
88
data = usf.read(" schedule.usf" )
89
+
90
+ # Add a new subject
65
91
usf.add_subject(data, {
66
92
" name" : " Physics" ,
67
93
" teacher" : " Prof. Johnson" ,
68
94
" location" : " Room 203" ,
69
- " time" : [( 3 , 4 ) ],
95
+ " time" : [3 , 4 ],
70
96
" week" : " odd"
71
97
})
98
+
99
+ # Save the updated schedule
72
100
usf.save(data, " updated_schedule.usf" )
73
101
```
74
102
75
103
### Generating a USF File from Scratch
76
104
``` python
105
+ import usf
106
+
107
+ # Initialize the USF Generator
77
108
schedule = usf.create()
109
+
110
+ # Add a subject
78
111
usf.add_subject(schedule, {
79
112
" name" : " Computer Science" ,
80
113
" teacher" : " Ms. Lee" ,
81
114
" location" : " Lab 2" ,
82
- " time" : [( 5 , 6 ) ],
115
+ " time" : [5 , 6 ],
83
116
" week" : " even"
84
117
})
118
+
119
+ # Save the new schedule
85
120
usf.save(schedule, " new_schedule.usf" )
86
121
```
87
122
0 commit comments