Skip to main content

A lightweight Universal Schedule Format (USF) parser and generator.

Project description

USF-Python

Language: English|简体中文

USF Access Framework for Python

Upload Python Package

When the newest release only contains description updates, upload to PyPI will be failed.

Introduction

USF-Python is a Python library that provides access to the USF format for efficiency and universality.

Features

  • Lightweight & Compact: Optimized for efficient storage and fast parsing.
  • Supports Course Schedules: Store course names, instructors, locations, time slots, and week rules.
  • Flexible Week Rules: Supports "all", "even", and "odd" week patterns.
  • Simple API: Easy to read, write, and manipulate USF files.
  • Cross-Platform: Works on all platforms supporting Python.

Installation

You can simply install the package with pip

pip install usf

or install it locally

python setup.py install

Usage

import usf

# Reading a USF file
data = usf.read("schedule.usf")
if usf.is_valid(data):
    print("Valid USF file")
    subjects = usf.get_subjects(data)
    print(subjects)
else:
    print("Invalid USF file")

# Creating a USF file
# Initialize the USF Generator (version 1 by default)
usf_generator = usf.USFGenerator()

# Add subjects
usf_generator.add_subject("Mathematics", simplified_name="Math", teacher="Dr. Smith", room="Room 101")
usf_generator.add_subject("Physics", simplified_name="Phys", teacher="Prof. Johnson", room="Room 203")

# Add class periods
usf_generator.add_period("08:00:00", "09:30:00")
usf_generator.add_period("10:00:00", "11:30:00")

# Add schedule entries
usf_generator.add_schedule(day=1, week_type="all", subject="Mathematics", period_index=1)  # Monday
usf_generator.add_schedule(day=2, week_type="odd", subject="Physics", period_index=2)  # Tuesday (Odd Week)

# Generate the USF data and save it to a file
usf_generator.save_to_file("schedule.usf")

# Adding a Course to an Existing USF File
data = usf.read("schedule.usf")
usf.add_subject(data, {
    "name": "Physics",
    "teacher": "Prof. Johnson",
    "location": "Room 203",
    "time": [3, 4],
    "week": "odd"
})
usf.save(data, "updated_schedule.usf")

# Generating a USF File from Scratch
schedule = usf.create()
usf.add_subject(schedule, {
    "name": "Computer Science",
    "teacher": "Ms. Lee",
    "location": "Lab 2",
    "time": [5, 6],
    "week": "even"
})
usf.save(schedule, "new_schedule.usf")

USF Format Specification

USF data is structured as a compact array:

  • name: Course name (string)
  • teacher: Instructor name (string)
  • location: Classroom or venue (string)
  • time: List of tuples representing periods, e.g., [(1, 2)] means periods 1 and 2
  • week: "all", "even", or "odd"

Example JSON representation:

{
  "version": 1,
  "subjects": {
    "Mathematics": {
      "simplified_name": "Math",
      "teacher": "Dr. Smith",
      "room": "Room 101"
    },
    "Physics": {
      "simplified_name": "Phys",
      "teacher": "Prof. Johnson",
      "room": "Room 203"
    }
  },
  "periods": [
    ["08:00:00", "09:30:00"],
    ["10:00:00", "11:30:00"]
  ],
  "timetable": [
    [1, "all", "Mathematics", 1],
    [2, "odd", "Physics", 2]
  ]
}

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usf-0.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usf-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file usf-0.2.0.tar.gz.

File metadata

  • Download URL: usf-0.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for usf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6fd322e4947be9903644ebe43dacb36b82f1e8c08fac850f1739a8a4a7ffb203
MD5 63697c9f74433c4a3ade25d8fa2fed6d
BLAKE2b-256 216aad209978835ff92dd7c8f2fabd2e9e95867e26823a8ad00399d033ead938

See more details on using hashes here.

Provenance

The following attestation bundles were made for usf-0.2.0.tar.gz:

Publisher: python-publish.yml on USF-org/USF-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usf-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: usf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for usf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5a9509cc4a6aeb94f83f6300c1fb392b45eb92e59b5c641af504a4af194eb90
MD5 3a9e94d5c2dc4f0a8d3972ec786db2f0
BLAKE2b-256 accaa16f6461aea50c6cf301b4bfea512d455e1e7694aed003e5d51c7975adf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for usf-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on USF-org/USF-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page