Automatic schedule for Kursk State Polytechnic College (KSPC)
Project description
schedule-kspc
Python библиотека, реализует автоматизированное расписание для Курского Государственного Политехнического Колледжа (КГПК). KSPS - Kursk State Polytechnic College.
- Установка последней версии модуля
pip install schedule-kspc
📂 DirManager
Упрощенная работа с файлами и директориями:
- Бинарное дерево
- Пример
import os
from schedule_kspc.DirManager import Tree, Node
if __name__ == '__main__':
# Create root node/tree
root_node = Node(name='root', path=os.getcwd())
dir_manger = Tree(root_node=root_node)
# Add node/child
dir_manger.add_node(root=root_node, name='child-1')
dir_manger.root_node.children[0].add_child(name='child-1-1')
# Add node/child
dir_manger.add_node(root=root_node, name='child-2')
dir_manger.root_node.children[1].add_child(name='child-2-1')
# Create folders
dir_manger.make_folders(node=root_node)
print(dir_manger)
-
Файловая структура:
root
├── child-1
│ └── child-1-1
└── child-2
└── child-2-1
Поиск релевантных файлов из выбранного каталога
- Выявление паттерна даты и упорядочивание по хронологической близости
import os
from random import randint
from datetime import datetime
from schedule_kspc.Store import DATETIME_PATTERN
from schedule_kspc.DirManager import Tree, Node, get_relevant_files
# Create file (random filename by datetime)
def create_file(path: str) -> None:
year, month, day = (
randint(2000, 2024),
randint(1, 12),
randint(1, 28)
)
hour, minute, second = (
randint(0, 23),
randint(0, 59),
randint(0, 59)
)
random_date: datetime = datetime(year, month, day, hour, minute, second)
filename: str = random_date.strftime(DATETIME_PATTERN)
file = open(f'{path}\\{filename}_schedule.txt', mode='w')
file.close()
# Create directory tree
def create_test_directory_tree() -> Tree:
root_node = Node(name='root', path=os.getcwd())
dir_manger = Tree(root_node=root_node)
dir_manger.make_folders(node=root_node)
return dir_manger
if __name__ == '__main__':
# Directory tree
tree = create_test_directory_tree()
# Test files
create_file(path=tree.root_node.path)
create_file(path=tree.root_node.path)
create_file(path=tree.root_node.path)
create_file(path=tree.root_node.path)
# Get all files in directory
print(tree.get_files(tree.root_node))
# Get relevant files
print(get_relevant_files(dir_tree=tree, dir_node=tree.root_node))
-
Файловая структура:
root:
├── 03.08.2012_10.07.20_schedule.txt
├── 13.07.2011_21.30.13_schedule.txt
├── 16.04.2023_13.20.12_schedule.txt
└── 17.11.2006_05.21.10_schedule.txt
-
Результат (Get all files in directory):
['03.08.2012_10.07.20_schedule.txt', '13.07.2011_21.30.13_schedule.txt', '16.04.2023_13.20.12_schedule.txt', '17.11.2006_05.21.10_schedule.txt']
-
Результат (Get relevant files):
{'root': ['16.04.2023_13.20.12_schedule.txt', '03.08.2012_10.07.20_schedule.txt', '13.07.2011_21.30.13_schedule.txt', '17.11.2006_05.21.10_schedule.txt']}
🌐 WebRequests
Упрощенная работа с асинхронными http запросами
- Поиск паттерна ссылки на html странице:
from schedule_kspc import Store
from schedule_kspc import WebRequests
@WebRequests.http_request
async def get_files():
files: list = await WebRequests.http_find_html_pattern(url=Store.URL["site"], pattern=Store.URL_FILE_PATTERN)
print(files)
if __name__ == "__main__":
get_files()
- Скачивание файлов по ссылке с указанием директории и названия файла (Пример)
from os import getcwd
from schedule_kspc import Store
from schedule_kspc import WebRequests
current_path: str = getcwd()
@WebRequests.http_request
async def download_files():
files: list = await WebRequests.http_find_html_pattern(url=Store.URL["site"], pattern=Store.URL_FILE_PATTERN)
for file in files:
await WebRequests.http_download_file(url=Store.URL['file'] + file[0], folder=current_path, filename=file[1])
if __name__ == "__main__":
download_files()
📅 ExcelParser
Автоматизированное чтение excel расписания
from schedule_kspc import ExcelParser
from schedule_kspc.Store import WEEKDAYS, LESSONS, Lesson
if __name__ == '__main__':
# Excel parser
xl_parser = ExcelParser(filename='example.xlsx')
# Parse schedule of sheetnames
schedule: dict = xl_parser.parse_schedule_sheetnames()
# Parse schedule of teachers
schedule_teachers: dict = xl_parser.parse_schedule_teachers()
...
📝 JsonAdapter
Автоматизированная запись данных в json файл
from schedule_kspc import JsonAdapter
if __name__ == '__main__':
# Json adapter
json_adapter = JsonAdapter(filename='file.json')
# Json adapter / create file & write data
json_adapter.write(
data={'example': [1, 2, 3, 4, 5], 'example-2': 'string', 'example-3': dict(example='string')},
indent=4, ensure_ascii=False
)
-
Результат:
file.json:
{
"example": [1, 2, 3, 4, 5],
"example-2": "string",
"example-3": {
"example": "string"
}
}
⚡ LoadSchedule
- Загрузка расписания, парсинг excel документа, сериализация в json файл:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
schedule_kspc-1.0.4.tar.gz
(10.7 kB
view details)
File details
Details for the file schedule_kspc-1.0.4.tar.gz
.
File metadata
- Download URL: schedule_kspc-1.0.4.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b35b426bc1b32cdf996ebd3a401fe249c3cddbcac9aadd571b555d2e0431999 |
|
MD5 | c6b22dc6b73f7216ae44a76d581ad3e3 |
|
BLAKE2b-256 | 47015624de1d6d6add280def290297f3b4d57361e09b80c64a731c505718b025 |