From 7f1337e412d6e18a043120152f031662c9068a04 Mon Sep 17 00:00:00 2001 From: klemek Date: Sat, 2 May 2020 15:42:59 +0200 Subject: [PATCH] code quality improvement --- meme_otron/img_factory.py | 1 - meme_otron/meme_db.py | 4 ++-- meme_otron/meme_otron.py | 1 - tools/calc.py | 19 +++++++++++-------- tools/live_edit.py | 5 ++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/meme_otron/img_factory.py b/meme_otron/img_factory.py index d533b06..2719af7 100644 --- a/meme_otron/img_factory.py +++ b/meme_otron/img_factory.py @@ -68,7 +68,6 @@ def build_text_only(texts: List[Text], debug: bool = False) -> Image.Image: range_factor = heights[i] / max_height start = sum(heights[:i]) / max_height text.y_range = (start + text.y_range[0] * range_factor, start + text.y_range[1] * range_factor) - pass txt_img = Image.new('RGBA', (TEXT_IMAGE_WIDTH, max_height), (255, 255, 255)) return apply_texts(txt_img, texts, debug=debug) diff --git a/meme_otron/meme_db.py b/meme_otron/meme_db.py index 5f9a4f9..3a1d3e5 100644 --- a/meme_otron/meme_db.py +++ b/meme_otron/meme_db.py @@ -91,8 +91,8 @@ def load_item(i: int, item: dict): meme.texts_len = current_text - 1 except TypeError as e: logger.warning(f"Item '{item_id}'({i + 1}) / Text {j + 1}: {e}") - for text in meme.texts: - text.update(meme.text_base) + for text in meme.texts: + text.update(meme.text_base) else: DATA[item_id] = meme if not meme.abstract: diff --git a/meme_otron/meme_otron.py b/meme_otron/meme_otron.py index 261dd06..e964b63 100644 --- a/meme_otron/meme_otron.py +++ b/meme_otron/meme_otron.py @@ -1,5 +1,4 @@ from typing import Optional, Tuple, List -import re from PIL import Image from io import BytesIO diff --git a/tools/calc.py b/tools/calc.py index 9182698..9e746d3 100644 --- a/tools/calc.py +++ b/tools/calc.py @@ -8,12 +8,15 @@ try: y0 = int(input("y0:")) w1 = int(input("w1:")) h1 = int(input("h1:")) - x1 = round(x0/w, 2) - y1 = round(y0/h, 2) - x2 = round((x0+w1)/w, 2) - y2 = round((y0+h1)/h, 2) - print(',{\n "x_range": '+f"[{x1:.2f}, {x2:.2f}]"+',\n "y_range": '+f"[{y1:.2f}, {y2:.2f}]"+'\n }') - except: + x1 = round(x0 / w, 2) + y1 = round(y0 / h, 2) + x2 = round((x0 + w1) / w, 2) + y2 = round((y0 + h1) / h, 2) + print( + ',{\n "x_range": ' + f"[{x1:.2f}, {x2:.2f}]" + ',\n "y_range": ' + f"[{y1:.2f}, {y2:.2f}]" + '\n }') + except ValueError: pass -except: - pass \ No newline at end of file +except ValueError: + pass +except KeyboardInterrupt: + pass diff --git a/tools/live_edit.py b/tools/live_edit.py index 430428e..c8e7f2a 100644 --- a/tools/live_edit.py +++ b/tools/live_edit.py @@ -3,7 +3,6 @@ import stat import time import datetime import logging -from os import path from meme_otron import img_factory from meme_otron import meme_db from meme_otron import utils @@ -16,7 +15,7 @@ db_file = utils.relative_path(__file__, "..", meme_db.DATA_FILE) templates_dir = utils.relative_path(__file__, "..", "templates") dst_dir = utils.relative_path(__file__, "tmp") -if not path.exists(dst_dir): +if not os.path.exists(dst_dir): os.mkdir(dst_dir) last = None @@ -32,6 +31,6 @@ while True: meme = meme_db.get_meme(meme_id) img = img_factory.build_from_template(meme.template, meme.texts, debug=True) if img is not None: - img.save(path.join(dst_dir, meme.template)) + img.save(os.path.join(dst_dir, meme.template)) count += 1 print(f"{datetime.datetime.now():%H:%M:%S} / {count} registered templates / {len(os.listdir(templates_dir))} files")