mirror of
https://github.com/szymon-jozef/zutui.git
synced 2026-06-05 17:00:11 +02:00
init
This commit is contained in:
216
.gitignore
vendored
Normal file
216
.gitignore
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[codz]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
# Pipfile.lock
|
||||
|
||||
# UV
|
||||
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# uv.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
# poetry.lock
|
||||
# poetry.toml
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
||||
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
||||
# pdm.lock
|
||||
# pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# pixi
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
||||
# pixi.lock
|
||||
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
||||
# in the .venv directory. It is recommended not to include this directory in version control.
|
||||
.pixi
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# Redis
|
||||
*.rdb
|
||||
*.aof
|
||||
*.pid
|
||||
|
||||
# RabbitMQ
|
||||
mnesia/
|
||||
rabbitmq/
|
||||
rabbitmq-data/
|
||||
|
||||
# ActiveMQ
|
||||
activemq-data/
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.envrc
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
# .idea/
|
||||
|
||||
# Abstra
|
||||
# Abstra is an AI-powered process automation framework.
|
||||
# Ignore directories containing user credentials, local state, and settings.
|
||||
# Learn more at https://abstra.io/docs
|
||||
.abstra/
|
||||
|
||||
# Visual Studio Code
|
||||
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
||||
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
||||
# you could uncomment the following to ignore the entire vscode folder
|
||||
# .vscode/
|
||||
|
||||
# Ruff stuff:
|
||||
.ruff_cache/
|
||||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
# Marimo
|
||||
marimo/_static/
|
||||
marimo/_lsp/
|
||||
__marimo__/
|
||||
|
||||
# Streamlit
|
||||
.streamlit/secrets.toml
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 s187
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
17
setup.py
Normal file
17
setup.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="zutui",
|
||||
version="1.0.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[
|
||||
"requests",
|
||||
"beautifulsoup4",
|
||||
"textual",
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'zutui=zut_app.zutui:main',
|
||||
],
|
||||
},
|
||||
)
|
||||
0
zut_app/__init__.py
Normal file
0
zut_app/__init__.py
Normal file
180
zut_app/zut_client.py
Normal file
180
zut_app/zut_client.py
Normal file
@@ -0,0 +1,180 @@
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import json
|
||||
import os
|
||||
|
||||
USER_HOME = os.path.expanduser("~")
|
||||
APP_DIR = os.path.join(USER_HOME, "zutui")
|
||||
if not os.path.exists(APP_DIR):
|
||||
os.makedirs(APP_DIR)
|
||||
|
||||
CACHE_FILE = os.path.join(APP_DIR, "grades_cache.json")
|
||||
TIMEOUT = 10
|
||||
|
||||
class ZUT:
|
||||
URLS = {
|
||||
"LOGIN": "https://edziekanat.zut.edu.pl/WU/Logowanie2.aspx",
|
||||
"FINAL": "https://edziekanat.zut.edu.pl/WU/OcenyP.aspx",
|
||||
"PARTIAL": "https://edziekanat.zut.edu.pl/WU/OcenyCzast.aspx",
|
||||
"NEWS": "https://edziekanat.zut.edu.pl/WU/News.aspx"
|
||||
}
|
||||
|
||||
def __init__(self, username, password):
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.session = requests.Session()
|
||||
self.session.headers.update({
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||
"Origin": "https://edziekanat.zut.edu.pl",
|
||||
})
|
||||
self.is_logged_in = False
|
||||
|
||||
def load_cache(self):
|
||||
if os.path.exists(CACHE_FILE):
|
||||
try:
|
||||
with open(CACHE_FILE, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
except:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
def save_cache(self, data):
|
||||
try:
|
||||
with open(CACHE_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||
except Exception as e:
|
||||
print(f"Failed to save cache: {e}")
|
||||
|
||||
def _get_hidden_inputs(self, soup):
|
||||
return {inp.get('name'): inp.get('value') for inp in soup.find_all('input', type='hidden') if inp.get('name')}
|
||||
|
||||
def login(self):
|
||||
try:
|
||||
self.session.headers.update({"Referer": self.URLS["LOGIN"]})
|
||||
r = self.session.get(self.URLS["LOGIN"], timeout=TIMEOUT)
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
payload = self._get_hidden_inputs(soup)
|
||||
|
||||
payload.update({
|
||||
'ctl00$ctl00$ContentPlaceHolder$MiddleContentPlaceHolder$txtIdent': self.username,
|
||||
'ctl00$ctl00$ContentPlaceHolder$MiddleContentPlaceHolder$txtHaslo': self.password,
|
||||
'ctl00$ctl00$ContentPlaceHolder$MiddleContentPlaceHolder$butLoguj': 'Zaloguj',
|
||||
'ctl00$ctl00$ContentPlaceHolder$MiddleContentPlaceHolder$rbKto': 'student'
|
||||
})
|
||||
|
||||
post_response = self.session.post(self.URLS["LOGIN"], data=payload, timeout=TIMEOUT)
|
||||
|
||||
if ".ASPX" in str(self.session.cookies.get_dict()) or "Wyloguj" in post_response.text:
|
||||
self.is_logged_in = True
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Login Error: {e}")
|
||||
return False
|
||||
|
||||
def get_final_grades(self):
|
||||
if not self.is_logged_in: return {}
|
||||
self.session.headers.update({"Referer": self.URLS["NEWS"]})
|
||||
try:
|
||||
resp = self.session.get(self.URLS["FINAL"], timeout=TIMEOUT)
|
||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
||||
|
||||
data = {}
|
||||
table = soup.find('table', id='ctl00_ctl00_ContentPlaceHolder_RightContentPlaceHolder_dgDane')
|
||||
if not table: return data
|
||||
|
||||
for row in table.find_all('tr', class_='gridDane'):
|
||||
cells = row.find_all('td')
|
||||
if not cells: continue
|
||||
|
||||
def parse_cell(c):
|
||||
txt = [t.strip() for t in c.stripped_strings]
|
||||
if not txt: return None
|
||||
return {"grade": txt[0], "date": txt[1] if len(txt)>1 else ""}
|
||||
|
||||
subject = cells[0].get_text(strip=True)
|
||||
ctype = cells[1].get_text(strip=True)
|
||||
key = f"{subject}_{ctype}"
|
||||
|
||||
data[key] = {
|
||||
"subject": subject,
|
||||
"type": ctype,
|
||||
"final_grades": {
|
||||
"term_1": parse_cell(cells[5]),
|
||||
"retake_1": parse_cell(cells[6]),
|
||||
"retake_2": parse_cell(cells[7]),
|
||||
"commission": parse_cell(cells[8]),
|
||||
},
|
||||
"partial_grades": []
|
||||
}
|
||||
return data
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def get_partial_grades(self):
|
||||
if not self.is_logged_in: return {}
|
||||
try:
|
||||
resp = self.session.get(self.URLS["PARTIAL"], timeout=TIMEOUT)
|
||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
||||
payload = self._get_hidden_inputs(soup)
|
||||
|
||||
payload.update({
|
||||
'__EVENTTARGET': 'ctl00$ctl00$ContentPlaceHolder$RightContentPlaceHolder$chb_ExpColAll',
|
||||
'__EVENTARGUMENT': '',
|
||||
'ctl00$ctl00$ContentPlaceHolder$RightContentPlaceHolder$chb_ExpColAll': 'on'
|
||||
})
|
||||
|
||||
resp_expanded = self.session.post(self.URLS["PARTIAL"], data=payload, timeout=TIMEOUT)
|
||||
soup_exp = BeautifulSoup(resp_expanded.text, 'html.parser')
|
||||
|
||||
partials_map = {}
|
||||
main_grid = soup_exp.find('table', id='ctl00_ctl00_ContentPlaceHolder_RightContentPlaceHolder_rg_Przedmioty_ctl00')
|
||||
if not main_grid: return {}
|
||||
|
||||
rows = main_grid.find_all('tr')
|
||||
current_key = None
|
||||
|
||||
for row in rows:
|
||||
classes = row.get('class', [])
|
||||
if ('rgRow' in classes or 'rgAltRow' in classes) and not row.find('table'):
|
||||
cells = row.find_all('td')
|
||||
if len(cells) > 2:
|
||||
subj = cells[1].get_text(strip=True)
|
||||
ctype = cells[2].get_text(strip=True)
|
||||
current_key = f"{subj}_{ctype}"
|
||||
|
||||
nested_table = row.find('table')
|
||||
if nested_table and current_key:
|
||||
grades_list = []
|
||||
for inner_row in nested_table.find_all('tr'):
|
||||
icells = inner_row.find_all('td')
|
||||
if len(icells) >= 4:
|
||||
g_val = icells[2].get_text(strip=True)
|
||||
if g_val:
|
||||
grades_list.append({
|
||||
"grade": g_val,
|
||||
"desc": icells[1].get_text(strip=True) if len(icells) > 1 else "",
|
||||
"date": icells[3].get_text(strip=True) if len(icells) > 3 else "",
|
||||
"teacher": icells[4].get_text(strip=True) if len(icells) > 4 else ""
|
||||
})
|
||||
partials_map[current_key] = grades_list
|
||||
return partials_map
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
def refresh_data(self):
|
||||
if not self.is_logged_in:
|
||||
if not self.login():
|
||||
return None
|
||||
try:
|
||||
finals = self.get_final_grades()
|
||||
partials = self.get_partial_grades()
|
||||
for key, p_grades in partials.items():
|
||||
if key in finals:
|
||||
finals[key]['partial_grades'] = p_grades
|
||||
self.save_cache(finals)
|
||||
return finals
|
||||
except Exception as e:
|
||||
print(f"Refresh error: {e}")
|
||||
return None
|
||||
423
zut_app/zutui.py
Normal file
423
zut_app/zutui.py
Normal file
@@ -0,0 +1,423 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Container
|
||||
from textual.widgets import Header, Footer, DataTable, Label, Button, Input
|
||||
from textual.screen import Screen
|
||||
from textual.binding import Binding
|
||||
|
||||
from .zut_client import ZUT
|
||||
|
||||
USER_HOME = os.path.expanduser("~")
|
||||
APP_DIR = os.path.join(USER_HOME, "zutui")
|
||||
if not os.path.exists(APP_DIR):
|
||||
os.makedirs(APP_DIR)
|
||||
|
||||
CONFIG_FILE = os.path.join(APP_DIR, "config.json")
|
||||
REFRESH_INTERVAL = 1800
|
||||
|
||||
class LoginScreen(Screen):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Container(
|
||||
Label("ZUT e-Dziekanat Login", id="login_title"),
|
||||
Input(placeholder="Login (ID)", id="user"),
|
||||
Input(placeholder="Hasło", password=True, id="pass"),
|
||||
Button("Zaloguj się", variant="primary", id="login_btn"),
|
||||
Label("", id="status_msg"),
|
||||
id="login_dialog"
|
||||
)
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.submit_login()
|
||||
|
||||
def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||
self.submit_login()
|
||||
|
||||
def submit_login(self):
|
||||
user = self.query_one("#user", Input).value
|
||||
password = self.query_one("#pass", Input).value
|
||||
|
||||
if not user or not password:
|
||||
self.query_one("#status_msg", Label).update("[!] Proszę wypełnić wszystkie pola.")
|
||||
return
|
||||
|
||||
self.app.zut_client = ZUT(user, password)
|
||||
self.query_one("#status_msg", Label).update("Trwa logowanie...")
|
||||
self.query_one("#login_btn", Button).disabled = True
|
||||
self.query_one("#user", Input).disabled = True
|
||||
self.query_one("#pass", Input).disabled = True
|
||||
|
||||
self.run_worker(self.perform_login_action(user, password), thread=True)
|
||||
|
||||
def perform_login_action(self, user, password):
|
||||
def job():
|
||||
success = self.app.zut_client.login()
|
||||
if success:
|
||||
try:
|
||||
with open(CONFIG_FILE, "w") as f:
|
||||
json.dump({"username": user, "password": password}, f)
|
||||
except: pass
|
||||
|
||||
def do_switch():
|
||||
self.app.switch_screen(DashboardScreen())
|
||||
self.app.call_from_thread(do_switch)
|
||||
else:
|
||||
def show_error():
|
||||
self.query_one("#status_msg", Label).update("[!] Błąd logowania.")
|
||||
self.query_one("#login_btn", Button).disabled = False
|
||||
self.query_one("#user", Input).disabled = False
|
||||
self.query_one("#pass", Input).disabled = False
|
||||
self.query_one("#pass", Input).focus()
|
||||
self.app.call_from_thread(show_error)
|
||||
return job
|
||||
|
||||
class DetailsScreen(Screen):
|
||||
BINDINGS = [("escape", "app.pop_screen", "Zamknij")]
|
||||
|
||||
def __init__(self, subject_data):
|
||||
super().__init__()
|
||||
self.subject_data = subject_data
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Container(
|
||||
Label(f"{self.subject_data['subject']} - Szczegóły", classes="details_title"),
|
||||
DataTable(id="details_table"),
|
||||
Button("Zamknij (Esc)", variant="error", id="close_btn"),
|
||||
classes="modal_container"
|
||||
)
|
||||
|
||||
def on_mount(self):
|
||||
table = self.query_one(DataTable)
|
||||
table.cursor_type = "row"
|
||||
table.zebra_stripes = True
|
||||
table.add_columns("Opis", "Ocena", "Data", "Nauczyciel")
|
||||
|
||||
partials = self.subject_data.get("partial_grades", [])
|
||||
|
||||
if not partials:
|
||||
table.add_row("Brak ocen cząstkowych", "-", "-", "-")
|
||||
else:
|
||||
for p in partials:
|
||||
val = p.get("grade", "-")
|
||||
color = "red" if "2" in val else "green"
|
||||
fmt_val = f"[{color}]{val}[/]"
|
||||
|
||||
table.add_row(
|
||||
p.get("desc", "-"),
|
||||
fmt_val,
|
||||
p.get("date", "-"),
|
||||
p.get("teacher", "-")
|
||||
)
|
||||
table.focus()
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
self.app.pop_screen()
|
||||
|
||||
class GradesTable(DataTable):
|
||||
BINDINGS = [
|
||||
Binding("enter", "select_cursor", "Pokaż szczegóły", priority=True)
|
||||
]
|
||||
|
||||
class DashboardScreen(Screen):
|
||||
BINDINGS = [
|
||||
("f5", "refresh_grades", "Odśwież dane")
|
||||
]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Container(
|
||||
Label("Twoje Oceny", classes="table_title"),
|
||||
Label("Ostatnia aktualizacja: Teraz", id="status_bar", classes="status_ok"),
|
||||
GradesTable(id="grades_table"),
|
||||
id="main_container"
|
||||
)
|
||||
yield Container(
|
||||
Label("F5 - Odśwież dane"),
|
||||
Label("Enter - szczegóły ocen cząstkowych"),
|
||||
id="info_container"
|
||||
)
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.current_data = {}
|
||||
table = self.query_one(GradesTable)
|
||||
table.cursor_type = "row"
|
||||
table.zebra_stripes = True
|
||||
table.add_columns("Przedmiot", "Typ", "Oceny Częściowe", "Semestr 1", "Poprawka 1", "Poprawka 2", "Komis")
|
||||
|
||||
cached_data = self.app.zut_client.load_cache()
|
||||
if cached_data:
|
||||
self.update_table(cached_data)
|
||||
self.query_one("#status_bar", Label).update("[+] Załadowano z pamięci. Odświeżanie...")
|
||||
else:
|
||||
self.query_one("#status_bar", Label).update("[?] Pobieranie danych...")
|
||||
table.loading = True
|
||||
|
||||
self.run_worker(self.refresh_data_worker, exclusive=True, thread=True)
|
||||
self.set_interval(REFRESH_INTERVAL, self.scheduled_refresh)
|
||||
|
||||
def action_refresh_grades(self):
|
||||
self.query_one("#status_bar", Label).update("[!] Wymuszanie odświeżania...")
|
||||
self.query_one(GradesTable).loading = True
|
||||
self.run_worker(self.refresh_data_worker, exclusive=True, thread=True)
|
||||
|
||||
def on_data_table_row_selected(self, event: DataTable.RowSelected):
|
||||
row_key = event.row_key.value
|
||||
if row_key and row_key in self.current_data:
|
||||
self.app.push_screen(DetailsScreen(self.current_data[row_key]))
|
||||
|
||||
def scheduled_refresh(self):
|
||||
self.query_one("#status_bar", Label).update("[?] Sprawdzanie aktualizacji...")
|
||||
self.run_worker(self.refresh_data_worker, exclusive=True, thread=True)
|
||||
|
||||
def refresh_data_worker(self):
|
||||
try:
|
||||
if not self.app.zut_client.is_logged_in:
|
||||
if not self.app.zut_client.login():
|
||||
self.app.call_from_thread(self.query_one("#status_bar", Label).update, "[!] Błąd ponownego logowania")
|
||||
return
|
||||
|
||||
new_data = self.app.zut_client.refresh_data()
|
||||
now = datetime.now().strftime("%H:%M:%S")
|
||||
|
||||
if new_data:
|
||||
self.app.call_from_thread(self.update_table, new_data)
|
||||
self.app.call_from_thread(self.query_one("#status_bar", Label).update, f"[+] Zaktualizowano: {now}")
|
||||
else:
|
||||
self.app.call_from_thread(self.query_one("#status_bar", Label).update, f"[!] Błąd sieci: {now}")
|
||||
|
||||
except Exception as e:
|
||||
self.app.call_from_thread(self.query_one("#status_bar", Label).update, f"[!] Błąd: {str(e)}")
|
||||
|
||||
finally:
|
||||
def stop_loading():
|
||||
try: self.query_one(GradesTable).loading = False
|
||||
except: pass
|
||||
self.app.call_from_thread(stop_loading)
|
||||
|
||||
def update_table(self, data):
|
||||
self.current_data = data
|
||||
table = self.query_one(GradesTable)
|
||||
table.clear()
|
||||
|
||||
for key, item in data.items():
|
||||
finals = item['final_grades']
|
||||
|
||||
def fmt_grade(g_obj):
|
||||
if not g_obj: return "-"
|
||||
val = g_obj['grade'].replace(',', '.')
|
||||
color = "red" if "2" in val else "green"
|
||||
return f"[{color}]{val}[/]"
|
||||
|
||||
partials_list = item.get('partial_grades', [])
|
||||
if partials_list:
|
||||
p_str_list = []
|
||||
for p in partials_list:
|
||||
raw_val = p['grade'].strip().replace(',', '.')
|
||||
p_str_list.append(f"[cyan]{raw_val}[/]")
|
||||
p_str = ", ".join(p_str_list)
|
||||
else:
|
||||
p_str = "[dim]-[/dim]"
|
||||
|
||||
table.add_row(
|
||||
f"[bold]{item['subject']}[/]", item['type'], p_str,
|
||||
fmt_grade(finals.get('term_1')), fmt_grade(finals.get('retake_1')),
|
||||
fmt_grade(finals.get('retake_2')), fmt_grade(finals.get('commission')),
|
||||
key=key
|
||||
)
|
||||
|
||||
class ZutApp(App):
|
||||
TITLE = "ZUT e-Dziekanat"
|
||||
CSS = """
|
||||
Screen {
|
||||
align: center middle;
|
||||
background: #0e0e0e;
|
||||
}
|
||||
|
||||
#login_dialog {
|
||||
width: 60;
|
||||
height: auto;
|
||||
border: solid rgb(40,40,40);
|
||||
padding: 1;
|
||||
background: #0e0e0e;
|
||||
|
||||
Input {
|
||||
background: rgb(20, 20, 20);
|
||||
border: wide rgb(40, 40, 40);
|
||||
color: rgb(225, 225, 225);
|
||||
height: auto;
|
||||
padding: 1;
|
||||
margin: 0 0;
|
||||
}
|
||||
|
||||
Button {
|
||||
background: rgb(30, 30, 30);
|
||||
border: wide rgb(40, 40, 40);
|
||||
width: 100%;
|
||||
padding: 1;
|
||||
margin: 0 0;
|
||||
&:hover { background: rgb(50, 50, 50); }
|
||||
&:disabled { background: rgb(20, 20, 20); color: rgb(80, 80, 80); }
|
||||
}
|
||||
}
|
||||
|
||||
#login_title {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
margin-bottom: 1;
|
||||
}
|
||||
|
||||
#status_msg {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
color: red;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#main_container {
|
||||
width: 100%;
|
||||
height: 1fr;
|
||||
padding: 1;
|
||||
background: #0e0e0e;
|
||||
border: wide #282828;
|
||||
}
|
||||
|
||||
.table_title {
|
||||
background: rgb(27,27,27);
|
||||
color: rgb(225,225,225);
|
||||
width: 100%;
|
||||
padding: 1 1;
|
||||
text-align: center;
|
||||
text-style: bold;
|
||||
border-left: wide #282828;
|
||||
border-right: wide #282828;
|
||||
border-top: wide #282828;
|
||||
}
|
||||
|
||||
#status_bar {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
background: rgb(19,19,19);
|
||||
color: #a0a0a0;
|
||||
padding: 1 1;
|
||||
border-left: wide #282828;
|
||||
border-right: wide #282828;
|
||||
border-bottom: wide #282828;
|
||||
}
|
||||
|
||||
#info_container {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
background: #0e0e0e;
|
||||
background-tint: black 0%;
|
||||
color: rgb(150, 150, 150);
|
||||
border: wide rgb(40, 40, 40);
|
||||
padding: 1 1;
|
||||
}
|
||||
|
||||
DataTable {
|
||||
height: 1fr;
|
||||
width: 100%;
|
||||
background: rgb(10, 10, 10);
|
||||
border: wide #282828;
|
||||
padding: 1;
|
||||
scrollbar-color: rgb(50, 50, 50);
|
||||
scrollbar-background: rgb(20, 20, 20);
|
||||
|
||||
&:focus {
|
||||
background-tint: black 0%;
|
||||
& > .datatable--cursor {
|
||||
background: rgb(60, 60, 60);
|
||||
}
|
||||
|
||||
& > .datatable--header {
|
||||
background-tint: black 0%;
|
||||
background: rgb(22, 22, 22);
|
||||
}
|
||||
|
||||
& > .datatable--fixed-cursor {
|
||||
color: $block-cursor-foreground;
|
||||
background: $block-cursor-background;
|
||||
}
|
||||
}
|
||||
|
||||
& > .datatable--even-row {
|
||||
background: rgb(15, 15, 15);
|
||||
}
|
||||
}
|
||||
|
||||
.modal_container {
|
||||
width: 80%;
|
||||
height: 80%;
|
||||
border: thick #282828;
|
||||
background: rgb(17, 17, 17);
|
||||
align: center middle;
|
||||
padding: 1;
|
||||
layout: vertical;
|
||||
}
|
||||
|
||||
.details_title {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
text-style: bold;
|
||||
background: rgb(19,19,19);
|
||||
color: rgb(225,225,225);
|
||||
margin-bottom: 1;
|
||||
padding: 1;
|
||||
}
|
||||
|
||||
#details_table {
|
||||
height: 1fr;
|
||||
width: 100%;
|
||||
margin-bottom: 1;
|
||||
background: rgb(17, 17, 17);
|
||||
border: wide #282828;
|
||||
|
||||
&:focus {
|
||||
background-tint: black 0%;
|
||||
& > .datatable--cursor {
|
||||
background: rgb(60, 60, 60);
|
||||
}
|
||||
|
||||
& > .datatable--header {
|
||||
background-tint: black 0%;
|
||||
background: rgb(22, 22, 22);
|
||||
}
|
||||
|
||||
& > .datatable--fixed-cursor {
|
||||
color: $block-cursor-foreground;
|
||||
background: $block-cursor-background;
|
||||
}
|
||||
}
|
||||
|
||||
& > .datatable--even-row {
|
||||
background: rgb(15, 15, 15);
|
||||
}
|
||||
}
|
||||
|
||||
#close_btn {
|
||||
width: 100%;
|
||||
}
|
||||
"""
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.zut_client = None
|
||||
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
try:
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
creds = json.load(f)
|
||||
self.zut_client = ZUT(creds["username"], creds["password"])
|
||||
self.push_screen(DashboardScreen())
|
||||
except:
|
||||
self.push_screen(LoginScreen())
|
||||
else:
|
||||
self.push_screen(LoginScreen())
|
||||
|
||||
def main():
|
||||
app = ZutApp()
|
||||
app.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user