From 1a32b70a2fab1475b1e2f8b230296b12590c9c37 Mon Sep 17 00:00:00 2001 From: "peter.fong" Date: Wed, 12 Feb 2025 16:46:57 +0000 Subject: [PATCH] qr code --- qrcodegen/qrcodegen.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/qrcodegen/qrcodegen.py b/qrcodegen/qrcodegen.py index fd8ef56..0b4aa3e 100644 --- a/qrcodegen/qrcodegen.py +++ b/qrcodegen/qrcodegen.py @@ -20,9 +20,24 @@ CLIENT_ID = os.getenv('SPOTIFY_CLIENT_ID') CLIENT_SECRET = os.getenv('SPOTIFY_CLIENT_SECRET') YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY') -# Configureren van logging -logging.basicConfig(filename="log.txt", level=logging.INFO, - format="%(asctime)s - %(message)s") +# # Configureren van logging +# logging.basicConfig(filename="log.txt", level=logging.INFO, +# format="%(asctime)s - %(message)s") + + +# Configureren van logging (naar bestand en console) +logger = logging.getLogger() +logger.setLevel(logging.INFO) + +# Log naar bestand +file_handler = logging.FileHandler("log.txt") +file_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s")) +logger.addHandler(file_handler) + +# Log naar console (stdout) +console_handler = logging.StreamHandler(sys.stdout) +console_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s")) +logger.addHandler(console_handler) def log_message(message): @@ -91,7 +106,8 @@ def get_x_pos(text, c, font, fontsize): def generate_qr_codes_and_pdf(csv_file, output_pdf, position_col, title_col, artist_col, year_col, platform): data = pd.read_csv(csv_file, delimiter=";") c = canvas.Canvas(output_pdf) - + total = data.shape[0] + i = 0 for _, row in data.iterrows(): position, title, artist, year = row[position_col], row[title_col], row[artist_col], row[year_col] url = get_spotify_track_url( @@ -105,9 +121,10 @@ def generate_qr_codes_and_pdf(csv_file, output_pdf, position_col, title_col, art qr_img = qr.make_image( fill='black', back_color='white').convert("RGB") - qr_image_path = f"temp_qr.png" + qr_image_path = f"{i}.png" qr_img.save(qr_image_path) - + i = i + 1 + log_message(f" saving -- {qr_image_path}, {i} out of {total}") qr_width, qr_height = qr_img.size page_width = qr_width + 100 page_height = qr_height + 200 @@ -117,8 +134,6 @@ def generate_qr_codes_and_pdf(csv_file, output_pdf, position_col, title_col, art c.drawImage(qr_image_path, 0, page_height - qr_height, width=qr_width, height=qr_height) - # c.drawImage(qr_image_path, x_center - (qr_width / 2), - # y_center, width=qr_width, height=qr_height) c.showPage() text_artist = f" {artist}" @@ -134,8 +149,6 @@ def generate_qr_codes_and_pdf(csv_file, output_pdf, position_col, title_col, art c.setFont("Courier", 11) c.drawString(get_x_pos(text_title, c, "Courier", 11), page_height - qr_height - 100, text_title) - # c.setFont("Helvetica", 12) - # c.drawString(50, page_height - qr_height - 100, text_url) c.showPage() os.remove(qr_image_path)