Translations, suggestion box, UX
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good

This commit is contained in:
2025-03-03 00:47:38 +01:00
parent 9f187afc22
commit 9361bc0363
17 changed files with 1515 additions and 135 deletions

View File

@@ -3,10 +3,11 @@ import subprocess
from bs4 import BeautifulSoup
import requests
from .I18N import _
from .settings import Settings
def open_tag_wiki_url(tag, settings: Settings):
def open_tag_wiki_url(tag: str, settings: Settings):
"""Otwiera w przeglądarce URL strony wiki dla podanego tagu."""
# Usuń prefiksy
for prefix in [
@@ -31,7 +32,7 @@ def open_webbrowser(url, settings: Settings):
subprocess.run([settings.browser, url], check=True)
return
except Exception as e:
print("Błąd przy otwieraniu przeglądarki:", e)
print(_("Błąd przy otwieraniu przeglądarki:"), e)
import webbrowser
webbrowser.open(url)
@@ -68,18 +69,18 @@ def login(settings: Settings):
shm_session = session.cookies.get("shm_session")
if not (shm_user and shm_session):
raise Exception("Login succeeded, but expected cookies were not set.")
raise Exception(_("Login succeeded, but expected cookies were not set."))
print("Login successful. Cookies stored in session:")
print(f"shm_user: {shm_user}")
print(f"shm_session: {shm_session}")
print(_("Login successful. Cookies stored in session."))
return session
else:
raise Exception(f"Login failed: {response.status_code} - {response.text}")
raise Exception(
f"{_('Login failed:')} {response.status_code} - {response.text}"
)
def get_auth_token(session, settings):
def get_auth_token(session: requests.Session, settings: Settings) -> str:
"""
Given a logged-in session and settings, fetch the user page
and extract the auth_token from the hidden input field.
@@ -91,7 +92,7 @@ def get_auth_token(session, settings):
# Retrieve the user identifier from cookies
shm_user = session.cookies.get("shm_user")
if not shm_user:
raise Exception("shm_user cookie not found; login might have failed.")
raise Exception(_("shm_user cookie not found; login might have failed."))
# Build the URL to fetch, e.g., /user/<shm_user>
user_url = f"{settings.base_url.rstrip('/')}/user/{shm_user}"
@@ -108,7 +109,9 @@ def get_auth_token(session, settings):
if response.status_code != 200:
raise Exception(
f"Failed to load {user_url}, status code: {response.status_code}"
_("Failed to load {user_url}, status code: {code}").format(
user_url=user_url, code=response.status_code
)
)
# Parse the returned HTML with BeautifulSoup
@@ -118,7 +121,7 @@ def get_auth_token(session, settings):
auth_input = soup.find("input", {"name": "auth_token"})
if auth_input and auth_input.has_attr("value"):
auth_token = auth_input["value"]
print(f"Found auth_token: {auth_token}")
print(_("Found auth_token:"), auth_token)
return auth_token
else:
raise Exception("auth_token not found in the HTML page.")
raise Exception(_("auth_token not found in the HTML page."))