mirror of
https://github.com/szymon-jozef/zutui.git
synced 2026-09-07 20:20:42 +02:00
Compare commits
2 Commits
feature/pa
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79baa5f1c6 | ||
| b4066e0c47 |
13
README.md
13
README.md
@@ -30,12 +30,17 @@ zutui
|
|||||||
`ctrl`+`q` - Quit
|
`ctrl`+`q` - Quit
|
||||||
|
|
||||||
# Sidenotes
|
# Sidenotes
|
||||||
## Config
|
- config is stored @ `~/zutui/config.json`
|
||||||
- On Unix like is stored @ `~/.config/zutui/config.json`
|
|
||||||
- On Windows is stored @ `~/zutui/config.json`
|
|
||||||
- so are `grades_cache.json`
|
- so are `grades_cache.json`
|
||||||
|
- in plaintext.....
|
||||||
|
|
||||||
##### Feel free to pull request if you're smarter :)
|
##### As of right now I don't see any MUCH better way.
|
||||||
|
|
||||||
|
##### I mean we could simply encrypt and decrypt it during runtime, but... does it really make it any more secure?
|
||||||
|
|
||||||
|
##### And we can't really store it in any form of a _hash_ as we have to log in everytime with plain text anyways...
|
||||||
|
|
||||||
|
##### However feel free to pull request if you're smarter :)
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
- [x] **Nothing**
|
- [x] **Nothing**
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -8,8 +8,6 @@ setup(
|
|||||||
"requests",
|
"requests",
|
||||||
"beautifulsoup4",
|
"beautifulsoup4",
|
||||||
"textual",
|
"textual",
|
||||||
"keyring",
|
|
||||||
"pywin32"
|
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import os
|
|
||||||
import platform
|
|
||||||
|
|
||||||
USER_HOME = os.path.expanduser("~")
|
|
||||||
WINDOWS_PATH = "zutui" # probably should be in %AppData% or something, but I'm not sure, so I won't change it
|
|
||||||
LINUX_PATH = ".config/zutui"
|
|
||||||
|
|
||||||
def get_config_path():
|
|
||||||
system = platform.system()
|
|
||||||
if system == "Windows":
|
|
||||||
APP_DIR = os.path.join(USER_HOME, WINDOWS_PATH)
|
|
||||||
elif system in ["Linux", "Darwin"]:
|
|
||||||
APP_DIR = os.path.join(USER_HOME, LINUX_PATH)
|
|
||||||
else:
|
|
||||||
print(f"System {system} not supported, aborting...")
|
|
||||||
exit(1)
|
|
||||||
if not os.path.exists(APP_DIR):
|
|
||||||
os.makedirs(APP_DIR)
|
|
||||||
return APP_DIR
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .config import get_config_path
|
USER_HOME = os.path.expanduser("~")
|
||||||
|
APP_DIR = os.path.join(USER_HOME, "zutui")
|
||||||
APP_DIR = get_config_path()
|
if not os.path.exists(APP_DIR):
|
||||||
|
os.makedirs(APP_DIR)
|
||||||
|
|
||||||
CACHE_FILE = os.path.join(APP_DIR, "grades_cache.json")
|
CACHE_FILE = os.path.join(APP_DIR, "grades_cache.json")
|
||||||
TIMEOUT = 10
|
TIMEOUT = 10
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import keyring
|
import time
|
||||||
from keyring.errors import KeyringError
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.containers import Container
|
from textual.containers import Container
|
||||||
@@ -10,9 +10,11 @@ from textual.screen import Screen
|
|||||||
from textual.binding import Binding
|
from textual.binding import Binding
|
||||||
|
|
||||||
from .zut_client import ZUT
|
from .zut_client import ZUT
|
||||||
from .config import get_config_path
|
|
||||||
|
|
||||||
APP_DIR = get_config_path()
|
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")
|
CONFIG_FILE = os.path.join(APP_DIR, "config.json")
|
||||||
REFRESH_INTERVAL = 1800
|
REFRESH_INTERVAL = 1800
|
||||||
@@ -56,20 +58,9 @@ class LoginScreen(Screen):
|
|||||||
if success:
|
if success:
|
||||||
try:
|
try:
|
||||||
with open(CONFIG_FILE, "w") as f:
|
with open(CONFIG_FILE, "w") as f:
|
||||||
json.dump({"username": user}, f)
|
json.dump({"username": user, "password": password}, f)
|
||||||
keyring.set_password("zutui", user, password)
|
|
||||||
except KeyringError as e:
|
|
||||||
error = e
|
|
||||||
self.app.call_from_thread(
|
|
||||||
lambda:
|
|
||||||
self.app.notify(
|
|
||||||
f"Błąd: {str(error)}",
|
|
||||||
title="Błąd zapisu hasła do systemowego menedżera haseł",
|
|
||||||
severity="warning",
|
|
||||||
timeout=5
|
|
||||||
)
|
|
||||||
)
|
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
def do_switch():
|
def do_switch():
|
||||||
self.app.switch_screen(DashboardScreen())
|
self.app.switch_screen(DashboardScreen())
|
||||||
self.app.call_from_thread(do_switch)
|
self.app.call_from_thread(do_switch)
|
||||||
@@ -419,10 +410,7 @@ class ZutApp(App):
|
|||||||
try:
|
try:
|
||||||
with open(CONFIG_FILE, "r") as f:
|
with open(CONFIG_FILE, "r") as f:
|
||||||
creds = json.load(f)
|
creds = json.load(f)
|
||||||
password = keyring.get_password("zutui", creds["username"])
|
self.zut_client = ZUT(creds["username"], creds["password"])
|
||||||
if password is None:
|
|
||||||
raise ValueError("Hasło nie zostało znalezione")
|
|
||||||
self.zut_client = ZUT(creds["username"], password)
|
|
||||||
self.push_screen(DashboardScreen())
|
self.push_screen(DashboardScreen())
|
||||||
except:
|
except:
|
||||||
self.push_screen(LoginScreen())
|
self.push_screen(LoginScreen())
|
||||||
|
|||||||
Reference in New Issue
Block a user