From b14793618d731d7a9574fa3e2f42da5900f9575e Mon Sep 17 00:00:00 2001 From: klemek Date: Mon, 27 Apr 2020 11:49:47 +0200 Subject: [PATCH] code cleaning --- discord_bot/__main__.py | 2 +- meme_otron/__init__.py | 1 + meme_otron/__main__.py | 6 +++++- meme_otron/img_factory.py | 12 +----------- meme_otron/meme_db.py | 8 -------- meme_otron/meme_otron.py | 4 ---- meme_otron/types.py | 15 --------------- 7 files changed, 8 insertions(+), 40 deletions(-) diff --git a/discord_bot/__main__.py b/discord_bot/__main__.py index f777586..b08fe1f 100644 --- a/discord_bot/__main__.py +++ b/discord_bot/__main__.py @@ -12,8 +12,8 @@ from meme_otron import img_factory as imgf from meme_otron import meme_db as db from meme_otron import utils from meme_otron import meme_otron +from meme_otron import VERSION -VERSION = "1.2-dev" DOC_URL = "https://github.com/klemek/meme-otron/tree/master/docs/README.md" t0 = datetime.now() logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.INFO) diff --git a/meme_otron/__init__.py b/meme_otron/__init__.py index e69de29..4f28c2e 100644 --- a/meme_otron/__init__.py +++ b/meme_otron/__init__.py @@ -0,0 +1 @@ +VERSION = "1.2-dev" diff --git a/meme_otron/__main__.py b/meme_otron/__main__.py index 0953b36..777ad7d 100644 --- a/meme_otron/__main__.py +++ b/meme_otron/__main__.py @@ -5,13 +5,17 @@ import os from . import img_factory as imgf from . import meme_db as db from . import meme_otron +from . import VERSION if __name__ == "__main__": db.load_memes() imgf.load_fonts() + # TODO better arguments reading (-h, -o, -v) + if len(sys.argv) <= 1 or sys.argv[1].lower().strip() == "help" or "-h" in sys.argv: - print("python -m meme_otron -h\n" + print(f"Meme-Otron v{VERSION}" + "python -m meme_otron -h\n" "python -m meme_otron (meme_id) \"[text 1]\" \"[text 2]\" ... > file.jpg\n" "python -m meme_otron -o file.jpg (meme_id) \"[text 1]\" \"[text 2]\" ...", file=sys.stderr) diff --git a/meme_otron/img_factory.py b/meme_otron/img_factory.py index 1ad08de..eed6264 100644 --- a/meme_otron/img_factory.py +++ b/meme_otron/img_factory.py @@ -14,9 +14,6 @@ logger = logging.getLogger("img_factory") def load_fonts(): - """ - TODO - """ for file in [f for f in os.listdir(FONT_DIR) if path.isfile(path.join(FONT_DIR, f))]: split = path.splitext(file) if split[-1] == ".ttf": @@ -29,8 +26,6 @@ def load_fonts(): def make(template, texts, debug=False): """ - TODO - :param (str) template: :param (list of Text) texts: :param (bool) debug: @@ -52,15 +47,11 @@ def make(template, texts, debug=False): def draw_text(draw, img, text, debug=False): """ - TODO - :param (PIL.ImageDraw.ImageDraw) draw: source image canvas :param (PIL.Image.Image) img: source image :param (Text) text: :param (bool) debug: """ - # TODO rotation - # https://stackoverflow.com/questions/245447/how-do-i-draw-text-at-an-angle-using-pythons-pil if text.text is not None and len(text.text.strip()) > 0: text.init() # load default values if text.font in FONTS: @@ -100,6 +91,7 @@ def fit_text(size, text): :rtype: (str, PIL.ImageFont.FreeTypeFont) :return: """ + # TODO rework this function max_width = round(size[0] * (text.x_range[1] - text.x_range[0])) max_height = round(size[1] * (text.y_range[1] - text.y_range[0])) text_size = None @@ -126,8 +118,6 @@ def fit_text(size, text): def get_pos(size, text, font, relative=False): """ - TODO - :param (int,int) size: source image size :param (Text) text: :param (PIL.ImageFont.FreeTypeFont) font: diff --git a/meme_otron/meme_db.py b/meme_otron/meme_db.py index b47d37b..d072323 100644 --- a/meme_otron/meme_db.py +++ b/meme_otron/meme_db.py @@ -15,8 +15,6 @@ logger = logging.getLogger("meme_db") def load_memes(purge=False): """ - TODO - :param (bool) purge: """ global DATA, ALIASES @@ -41,8 +39,6 @@ def load_memes(purge=False): def load_item(i, item): """ - TODO - :param (int) i: :param (dict) item: """ @@ -123,8 +119,6 @@ def load_item(i, item): def load_text(c, raw_text, text=None): """ - TODO - :param (int) c: :param (dict) raw_text: :param (Text|None) text: @@ -158,8 +152,6 @@ def load_text(c, raw_text, text=None): def get_meme(name): """ - TODO - :param (str) name: :rtype: Meme|None :return: diff --git a/meme_otron/meme_otron.py b/meme_otron/meme_otron.py index 7f8f4d7..a312922 100644 --- a/meme_otron/meme_otron.py +++ b/meme_otron/meme_otron.py @@ -23,8 +23,6 @@ left_wmark.y_range = [0.005, 0.995] def parse_text(s): """ - TODO - :param (str) s: :rtype: str """ @@ -33,8 +31,6 @@ def parse_text(s): def compute(*args, left_wmark_text=None, debug=False): """ - TODO - :param (str) left_wmark_text: :param (bool) debug: :param (str) args: diff --git a/meme_otron/types.py b/meme_otron/types.py index fc59c85..1516f1d 100644 --- a/meme_otron/types.py +++ b/meme_otron/types.py @@ -6,9 +6,6 @@ DEFAULT_FONT_SIZE = 0.05 class Pos(IntEnum): - """ - TODO - """ NW = 0 N = 1 NE = 2 @@ -21,10 +18,6 @@ class Pos(IntEnum): class Meme: - """ - TODO - """ - def __init__(self, meme_id): self.id = meme_id self.aliases = [] @@ -40,9 +33,6 @@ class Meme: class Text: - """ - TODO - """ base_properties = ["font", "font_size", "fill", "stroke_width", "stroke_fill", "align", "position"] @@ -68,8 +58,6 @@ class Text: def update(self, base): """ - TODO - :param (Text) base: """ for prop in Text.base_properties: @@ -77,9 +65,6 @@ class Text: setattr(self, prop, getattr(base, prop)) def init(self): - """ - TODO - """ if self.x_range is None: self.x_range = (0, 1) if self.y_range is None: