Skip to content

Commit a5588ec

Browse files
Update README.md
1 parent 1705603 commit a5588ec

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

README.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,38 @@ python setup.py install
2727
```python
2828
import usf
2929

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")
3556
else:
36-
print("Invalid USF file")
57+
print("Invalid USF data")
3758
```
3859

3960
### Creating a USF file
40-
```python
61+
···python
4162
import usf
4263

4364
# 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
5778

5879
# Generate the USF data and save it to a file
5980
usf_generator.save_to_file("schedule.usf")
60-
```
81+
···
6182

6283
### Adding a Course to an Existing USF File
6384
```python
85+
import usf
86+
87+
# Initialize the USF Parser
6488
data = usf.read("schedule.usf")
89+
90+
# Add a new subject
6591
usf.add_subject(data, {
6692
"name": "Physics",
6793
"teacher": "Prof. Johnson",
6894
"location": "Room 203",
69-
"time": [(3, 4)],
95+
"time": [3, 4],
7096
"week": "odd"
7197
})
98+
99+
# Save the updated schedule
72100
usf.save(data, "updated_schedule.usf")
73101
```
74102

75103
### Generating a USF File from Scratch
76104
```python
105+
import usf
106+
107+
# Initialize the USF Generator
77108
schedule = usf.create()
109+
110+
# Add a subject
78111
usf.add_subject(schedule, {
79112
"name": "Computer Science",
80113
"teacher": "Ms. Lee",
81114
"location": "Lab 2",
82-
"time": [(5, 6)],
115+
"time": [5, 6],
83116
"week": "even"
84117
})
118+
119+
# Save the new schedule
85120
usf.save(schedule, "new_schedule.usf")
86121
```
87122

0 commit comments

Comments
 (0)