edit requirements.txt, edit README.md, change to pymysql
This commit is contained in:
parent
7683a2697f
commit
b970ac5377
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,3 +2,6 @@
|
|||||||
test.pdf
|
test.pdf
|
||||||
.idea
|
.idea
|
||||||
files
|
files
|
||||||
|
config.toml
|
||||||
|
venv
|
||||||
|
__pycache__
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
### Step 1: Preparing configuration
|
### 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.
|
The system running the script needs access to the database server, or a current local database instance must be running.
|
||||||
|
|
||||||
### Step 2: Install dependencies
|
### 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
|
### Step 3: Execute
|
||||||
|
|
||||||
@ -15,5 +17,6 @@ Execute `ezgg_badge_generator.py`.
|
|||||||
|
|
||||||
|
|
||||||
### Further
|
### Further
|
||||||
|
The diagram shows the process of the script.
|
||||||
|
|
||||||

|

|
||||||
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 |
@ -1,14 +1,12 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from services.DatabaseService import DatabaseService
|
from services.DatabaseService import DatabaseService
|
||||||
from services.BadgeGeneratorService import BadgeGeneratorService
|
from services.BadgeGeneratorService import BadgeGeneratorService
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
def main():
|
||||||
db = DatabaseService("config.toml")
|
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")
|
badge_generator = BadgeGeneratorService("config.toml")
|
||||||
|
|
||||||
@ -21,4 +19,4 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
main()
|
||||||
|
|||||||
BIN
helpers/puffy.otf
Normal file
BIN
helpers/puffy.otf
Normal file
Binary file not shown.
@ -1,2 +1,2 @@
|
|||||||
aiomysql~=0.3.2
|
|
||||||
Jinja2~=3.1.6
|
Jinja2~=3.1.6
|
||||||
|
PyMySQL~=1.1.2
|
||||||
@ -69,6 +69,9 @@ class BadgeGeneratorService:
|
|||||||
f"--print-to-pdf={output_path.resolve()}",
|
f"--print-to-pdf={output_path.resolve()}",
|
||||||
html_path.resolve()
|
html_path.resolve()
|
||||||
], check=True)
|
], check=True)
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.error(f"Browser not found. {self.browser_path}")
|
||||||
|
exit(-1)
|
||||||
finally:
|
finally:
|
||||||
html_path.unlink(missing_ok=True)
|
html_path.unlink(missing_ok=True)
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import tomllib
|
import tomllib
|
||||||
import aiomysql
|
import pymysql
|
||||||
from typing import Optional
|
from typing import Optional, List, Dict
|
||||||
|
|
||||||
logger = logging.getLogger(__name__.split(".")[-1])
|
logger = logging.getLogger(__name__.split(".")[-1])
|
||||||
|
|
||||||
@ -12,25 +12,21 @@ class DatabaseService:
|
|||||||
config = tomllib.load(f)
|
config = tomllib.load(f)
|
||||||
|
|
||||||
self.db_config = config["database"]
|
self.db_config = config["database"]
|
||||||
self._pool: Optional[aiomysql.Pool] = None
|
self._conn: Optional[pymysql.Connection] = None
|
||||||
|
|
||||||
async def init_db_pool(self):
|
def init_db(self):
|
||||||
self._pool = await aiomysql.create_pool(
|
self._conn = pymysql.connect(
|
||||||
host=self.db_config["db_host"],
|
host=self.db_config["db_host"],
|
||||||
port=self.db_config["db_port"],
|
port=self.db_config["db_port"],
|
||||||
user=self.db_config["db_user"],
|
user=self.db_config["db_user"],
|
||||||
password=self.db_config["db_password"],
|
password=self.db_config["db_password"],
|
||||||
db=self.db_config["db_name"],
|
database=self.db_config["db_name"],
|
||||||
minsize=1,
|
cursorclass=pymysql.cursors.DictCursor)
|
||||||
maxsize=40,
|
|
||||||
autocommit=True
|
|
||||||
)
|
|
||||||
logger.info("Connected to database.")
|
logger.info("Connected to database.")
|
||||||
|
|
||||||
async def get_user_badges(self) -> list:
|
def get_user_badges(self) -> List[Dict]:
|
||||||
async with self._pool.acquire() as conn:
|
with self._conn.cursor() as cursor:
|
||||||
async with conn.cursor(aiomysql.DictCursor) as cursor:
|
cursor.execute(
|
||||||
await cursor.execute(
|
|
||||||
"""SELECT u.user_id, u.user_name, s.seat_id, upp.picture
|
"""SELECT u.user_id, u.user_name, s.seat_id, upp.picture
|
||||||
FROM users AS u
|
FROM users AS u
|
||||||
LEFT JOIN seats AS s
|
LEFT JOIN seats AS s
|
||||||
@ -38,4 +34,6 @@ class DatabaseService:
|
|||||||
LEFT JOIN user_profile_picture AS upp
|
LEFT JOIN user_profile_picture AS upp
|
||||||
ON u.user_id = upp.user_id;"""
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user