1
1
# USF-Python
2
+ Language: English|<a href =" ./README_zh.md " >简体中文</a >
3
+
2
4
USF Access Framework for Python
3
5
6
+ [ ![ Upload Python Package] ( https://github.com/USF-org/USF-Python/actions/workflows/python-publish.yml/badge.svg )] ( https://github.com/USF-org/USF-Python/actions/workflows/python-publish.yml )
7
+
8
+ When the newest release only contains description updates, upload to PyPI will be failed.
9
+
4
10
## Introduction
5
11
USF-Python is a Python library that provides access to the USF format for efficiency and universality.
6
12
@@ -22,56 +28,55 @@ python setup.py install
22
28
```
23
29
24
30
## Usage
25
-
26
- ### Reading a USF file
27
31
``` python
28
32
import usf
29
33
34
+ # Reading a USF file
30
35
data = usf.read(" schedule.usf" )
31
36
if usf.is_valid(data):
32
37
print (" Valid USF file" )
33
38
subjects = usf.get_subjects(data)
34
39
print (subjects)
35
40
else :
36
41
print (" Invalid USF file" )
37
- ```
38
42
39
- ### Creating a USF file
40
- ``` python
41
- schedule = usf.create ()
43
+ # Creating a USF file
44
+ # Initialize the USF Generator (version 1 by default)
45
+ usf_generator = usf.USFGenerator ()
42
46
43
- definition = {
44
- " name" : " Mathematics" ,
45
- " teacher" : " Dr. Smith" ,
46
- " location" : " Room 101" ,
47
- " time" : [(1 , 2 )], # Periods
48
- " week" : " all" # Every week
49
- }
50
- usf.add_subject(schedule, definition)
51
- usf.save(schedule, " my_schedule.usf" )
52
- ```
47
+ # Add subjects
48
+ usf_generator.add_subject(" Mathematics" , simplified_name = " Math" , teacher = " Dr. Smith" , room = " Room 101" )
49
+ usf_generator.add_subject(" Physics" , simplified_name = " Phys" , teacher = " Prof. Johnson" , room = " Room 203" )
53
50
54
- ### Adding a Course to an Existing USF File
55
- ``` python
51
+ # Add class periods
52
+ usf_generator.add_period(" 08:00:00" , " 09:30:00" )
53
+ usf_generator.add_period(" 10:00:00" , " 11:30:00" )
54
+
55
+ # Add schedule entries
56
+ usf_generator.add_schedule(day = 1 , week_type = " all" , subject = " Mathematics" , period_index = 1 ) # Monday
57
+ usf_generator.add_schedule(day = 2 , week_type = " odd" , subject = " Physics" , period_index = 2 ) # Tuesday (Odd Week)
58
+
59
+ # Generate the USF data and save it to a file
60
+ usf_generator.save_to_file(" schedule.usf" )
61
+
62
+ # Adding a Course to an Existing USF File
56
63
data = usf.read(" schedule.usf" )
57
64
usf.add_subject(data, {
58
65
" name" : " Physics" ,
59
66
" teacher" : " Prof. Johnson" ,
60
67
" location" : " Room 203" ,
61
- " time" : [( 3 , 4 ) ],
68
+ " time" : [3 , 4 ],
62
69
" week" : " odd"
63
70
})
64
71
usf.save(data, " updated_schedule.usf" )
65
- ```
66
72
67
- ### Generating a USF File from Scratch
68
- ``` python
73
+ # Generating a USF File from Scratch
69
74
schedule = usf.create()
70
75
usf.add_subject(schedule, {
71
76
" name" : " Computer Science" ,
72
77
" teacher" : " Ms. Lee" ,
73
78
" location" : " Lab 2" ,
74
- " time" : [( 5 , 6 ) ],
79
+ " time" : [5 , 6 ],
75
80
" week" : " even"
76
81
})
77
82
usf.save(schedule, " new_schedule.usf" )
@@ -88,15 +93,27 @@ USF data is structured as a compact array:
88
93
Example JSON representation:
89
94
``` json
90
95
{
91
- "subjects" : [
92
- {
93
- "name" : " Mathematics" ,
94
- "teacher" : " Dr. Smith" ,
95
- "location" : " Room 101" ,
96
- "time" : [[1 , 2 ]],
97
- "week" : " all"
98
- }
99
- ]
96
+ "version" : 1 ,
97
+ "subjects" : {
98
+ "Mathematics" : {
99
+ "simplified_name" : " Math" ,
100
+ "teacher" : " Dr. Smith" ,
101
+ "room" : " Room 101"
102
+ },
103
+ "Physics" : {
104
+ "simplified_name" : " Phys" ,
105
+ "teacher" : " Prof. Johnson" ,
106
+ "room" : " Room 203"
107
+ }
108
+ },
109
+ "periods" : [
110
+ [" 08:00:00" , " 09:30:00" ],
111
+ [" 10:00:00" , " 11:30:00" ]
112
+ ],
113
+ "timetable" : [
114
+ [1 , " all" , " Mathematics" , 1 ],
115
+ [2 , " odd" , " Physics" , 2 ]
116
+ ]
100
117
}
101
118
```
102
119
0 commit comments