edit requirements.txt, edit README.md, change to pymysql

This commit is contained in:
tcprod 2026-04-04 14:54:29 +02:00
parent 7683a2697f
commit b970ac5377
9 changed files with 38 additions and 33 deletions

5
.gitignore vendored
View File

@ -1,4 +1,7 @@
.venv
test.pdf
.idea
files
files
config.toml
venv
__pycache__

View File

@ -1,13 +1,15 @@
### Step 1: Preparing configuration
Prepare the `config.toml` at the base of the repository. It is important to adjust the database configuration as well as the `browser_path`.
Use the example configuration at `helpers/config.example.toml` to create a `config.toml` at the base of the repository.
It is important to adjust the database configuration as well as the `browser_path`. The script has only been tested with the Chrome browser.
The system running the script needs access to the database server, or a current local database instance must be running.
### Step 2: Install dependencies
Use `pip install -r requirements.txt` to install the requirements. The usage of a venv is recommended.
Use `pip install -r requirements.txt` to install the requirements. The use of a venv is recommended.
Install the `helpers/puffy.otf` font on your system.
### Step 3: Execute
@ -15,5 +17,6 @@ Execute `ezgg_badge_generator.py`.
### Further
The diagram shows the process of the script.
![activity diagram](activity_diagram.svg)

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -1,14 +1,12 @@
import asyncio
from services.DatabaseService import DatabaseService
from services.BadgeGeneratorService import BadgeGeneratorService
async def main():
def main():
db = DatabaseService("config.toml")
await db.init_db_pool()
db.init_db()
badges = await db.get_user_badges()
badges = db.get_user_badges()
badge_generator = BadgeGeneratorService("config.toml")
@ -21,4 +19,4 @@ async def main():
if __name__ == "__main__":
asyncio.run(main())
main()

BIN
helpers/puffy.otf Normal file

Binary file not shown.

View File

@ -1,2 +1,2 @@
aiomysql~=0.3.2
Jinja2~=3.1.6
Jinja2~=3.1.6
PyMySQL~=1.1.2

View File

@ -69,6 +69,9 @@ class BadgeGeneratorService:
f"--print-to-pdf={output_path.resolve()}",
html_path.resolve()
], check=True)
except FileNotFoundError:
logger.error(f"Browser not found. {self.browser_path}")
exit(-1)
finally:
html_path.unlink(missing_ok=True)

View File

@ -1,7 +1,7 @@
import logging
import tomllib
import aiomysql
from typing import Optional
import pymysql
from typing import Optional, List, Dict
logger = logging.getLogger(__name__.split(".")[-1])
@ -12,30 +12,28 @@ class DatabaseService:
config = tomllib.load(f)
self.db_config = config["database"]
self._pool: Optional[aiomysql.Pool] = None
self._conn: Optional[pymysql.Connection] = None
async def init_db_pool(self):
self._pool = await aiomysql.create_pool(
def init_db(self):
self._conn = pymysql.connect(
host=self.db_config["db_host"],
port=self.db_config["db_port"],
user=self.db_config["db_user"],
password=self.db_config["db_password"],
db=self.db_config["db_name"],
minsize=1,
maxsize=40,
autocommit=True
)
database=self.db_config["db_name"],
cursorclass=pymysql.cursors.DictCursor)
logger.info("Connected to database.")
async def get_user_badges(self) -> list:
async with self._pool.acquire() as conn:
async with conn.cursor(aiomysql.DictCursor) as cursor:
await cursor.execute(
"""SELECT u.user_id, u.user_name, s.seat_id, upp.picture
FROM users AS u
LEFT JOIN seats AS s
ON u.user_id = s.`user`
LEFT JOIN user_profile_picture AS upp
def get_user_badges(self) -> List[Dict]:
with self._conn.cursor() as cursor:
cursor.execute(
"""SELECT u.user_id, u.user_name, s.seat_id, upp.picture
FROM users AS u
LEFT JOIN seats AS s
ON u.user_id = s.`user`
LEFT JOIN user_profile_picture AS upp
ON u.user_id = upp.user_id;"""
)
return await cursor.fetchall()
)
user_badges = cursor.fetchall()
logger.info(f"Got {len(user_badges)} user badges from database.")
return user_badges