diff --git a/.gitignore b/.gitignore
index d91c3ff..ee25f7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
.venv
test.pdf
.idea
-files
\ No newline at end of file
+files
+config.toml
+venv
+__pycache__
diff --git a/README.md b/README.md
index a55611c..cfc8bb5 100644
--- a/README.md
+++ b/README.md
@@ -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.

\ No newline at end of file
diff --git a/activity_diagram.svg b/activity_diagram.svg
index 60256af..06f2cdd 100644
--- a/activity_diagram.svg
+++ b/activity_diagram.svg
@@ -1,4 +1,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/ezgg_badge_generator.py b/ezgg_badge_generator.py
index bd879a5..575b77e 100644
--- a/ezgg_badge_generator.py
+++ b/ezgg_badge_generator.py
@@ -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()
diff --git a/config.toml b/helpers/config.toml.example
similarity index 100%
rename from config.toml
rename to helpers/config.toml.example
diff --git a/helpers/puffy.otf b/helpers/puffy.otf
new file mode 100644
index 0000000..70c6d41
Binary files /dev/null and b/helpers/puffy.otf differ
diff --git a/requirements.txt b/requirements.txt
index 6612794..c050e27 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,2 @@
-aiomysql~=0.3.2
-Jinja2~=3.1.6
\ No newline at end of file
+Jinja2~=3.1.6
+PyMySQL~=1.1.2
\ No newline at end of file
diff --git a/services/BadgeGeneratorService.py b/services/BadgeGeneratorService.py
index f76f036..d29d2e5 100644
--- a/services/BadgeGeneratorService.py
+++ b/services/BadgeGeneratorService.py
@@ -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)
diff --git a/services/DatabaseService.py b/services/DatabaseService.py
index 501291d..a8ad32e 100644
--- a/services/DatabaseService.py
+++ b/services/DatabaseService.py
@@ -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