code quality improvement

This commit is contained in:
klemek
2020-05-02 15:42:59 +02:00
parent 839aff11f7
commit 7f1337e412
5 changed files with 15 additions and 15 deletions
-1
View File
@@ -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)
+2 -2
View File
@@ -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:
-1
View File
@@ -1,5 +1,4 @@
from typing import Optional, Tuple, List
import re
from PIL import Image
from io import BytesIO
+11 -8
View File
@@ -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
except ValueError:
pass
except KeyboardInterrupt:
pass
+2 -3
View File
@@ -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")