|
1 |
| -# USF-Python |
| 1 | +# USF-Python |
| 2 | +USF Access Framework for Python |
| 3 | + |
| 4 | +## Introduction |
| 5 | +USF-Python is a Python library that provides access to the USF format for efficiency and universality. |
| 6 | + |
| 7 | +## Features |
| 8 | +- **Lightweight & Compact**: Optimized for efficient storage and fast parsing. |
| 9 | +- **Supports Course Schedules**: Store course names, instructors, locations, time slots, and week rules. |
| 10 | +- **Flexible Week Rules**: Supports "all", "even", and "odd" week patterns. |
| 11 | +- **Simple API**: Easy to read, write, and manipulate USF files. |
| 12 | +- **Cross-Platform**: Works on all platforms supporting Python. |
| 13 | + |
| 14 | +## Installation |
| 15 | +You can simply install the package with **pip** |
| 16 | +```sh |
| 17 | +pip install usf |
| 18 | +``` |
| 19 | +or install it locally |
| 20 | +```sh |
| 21 | +python setup.py install |
| 22 | +``` |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### Reading a USF file |
| 27 | +```python |
| 28 | +import usf |
| 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) |
| 35 | +else: |
| 36 | + print("Invalid USF file") |
| 37 | +``` |
| 38 | + |
| 39 | +### Creating a USF file |
| 40 | +```python |
| 41 | +schedule = usf.create() |
| 42 | + |
| 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 | +``` |
| 53 | + |
| 54 | +### Adding a Course to an Existing USF File |
| 55 | +```python |
| 56 | +data = usf.read("schedule.usf") |
| 57 | +usf.add_subject(data, { |
| 58 | + "name": "Physics", |
| 59 | + "teacher": "Prof. Johnson", |
| 60 | + "location": "Room 203", |
| 61 | + "time": [(3, 4)], |
| 62 | + "week": "odd" |
| 63 | +}) |
| 64 | +usf.save(data, "updated_schedule.usf") |
| 65 | +``` |
| 66 | + |
| 67 | +### Generating a USF File from Scratch |
| 68 | +```python |
| 69 | +schedule = usf.create() |
| 70 | +usf.add_subject(schedule, { |
| 71 | + "name": "Computer Science", |
| 72 | + "teacher": "Ms. Lee", |
| 73 | + "location": "Lab 2", |
| 74 | + "time": [(5, 6)], |
| 75 | + "week": "even" |
| 76 | +}) |
| 77 | +usf.save(schedule, "new_schedule.usf") |
| 78 | +``` |
| 79 | + |
| 80 | +## USF Format Specification |
| 81 | +USF data is structured as a compact array: |
| 82 | +- **name**: Course name (string) |
| 83 | +- **teacher**: Instructor name (string) |
| 84 | +- **location**: Classroom or venue (string) |
| 85 | +- **time**: List of tuples representing periods, e.g., `[(1, 2)]` means periods 1 and 2 |
| 86 | +- **week**: `"all"`, `"even"`, or `"odd"` |
| 87 | + |
| 88 | +Example JSON representation: |
| 89 | +```json |
| 90 | +{ |
| 91 | + "subjects": [ |
| 92 | + { |
| 93 | + "name": "Mathematics", |
| 94 | + "teacher": "Dr. Smith", |
| 95 | + "location": "Room 101", |
| 96 | + "time": [[1, 2]], |
| 97 | + "week": "all" |
| 98 | + } |
| 99 | + ] |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +## Contributing |
| 104 | +Contributions are welcome! Feel free to open issues or submit pull requests on GitHub. |
| 105 | + |
| 106 | +## License |
| 107 | +This project is licensed under the MIT License. |
| 108 | + |
0 commit comments