diff --git a/.gitignore b/.gitignore index 451fb35..bfccb2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env -.idea \ No newline at end of file +.idea +__pycache__ \ No newline at end of file diff --git a/discord_bot/__init__.py b/discord_bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/discord/bot.py b/discord_bot/main.py similarity index 100% rename from discord/bot.py rename to discord_bot/main.py diff --git a/discord/requirements.txt b/discord_bot/requirements.txt similarity index 100% rename from discord/requirements.txt rename to discord_bot/requirements.txt diff --git a/docs/__init__.py b/docs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/docs/build_docs.py b/docs/build_docs.py index 92a17c7..31c4d69 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -3,23 +3,23 @@ import logging from os import path from meme_otron import img_factory as imgf from meme_otron import meme_db +from meme_otron import utils logging.basicConfig(format="[%(asctime)s][%(levelname)s][%(module)s] %(message)s", level=logging.DEBUG) imgf.load_fonts() meme_db.load_memes() -dst_dir = path.abspath("templates") +dst_dir = utils.relative_path(__file__, "templates") for f in os.listdir(dst_dir): if path.isfile(path.join(dst_dir, f)): os.unlink(path.join(dst_dir, f)) - for meme_id in meme_db.DATA: meme = meme_db.get_meme(meme_id) if meme is not None: img = imgf.make(meme.template, meme.texts, debug=True) - img.save(path.join(dst_dir, meme.template)) - print(meme_id) - + if img is not None: + img.save(path.join(dst_dir, meme.template)) + print(meme_id) diff --git a/meme_otron/img_factory.py b/meme_otron/img_factory.py index 893b607..ef1450b 100644 --- a/meme_otron/img_factory.py +++ b/meme_otron/img_factory.py @@ -3,11 +3,13 @@ import os import os.path as path import logging +from . import utils + DEFAULT_FONT = "arial" DEFAULT_FONT_SIZE = 0.05 -FONT_DIR = "../fonts" -TEMPLATES_DIR = "../templates" +FONT_DIR = utils.relative_path(__file__, "..", "fonts") +TEMPLATES_DIR = utils.relative_path(__file__, "..", "templates") FONTS = {} diff --git a/meme_otron/meme_db.py b/meme_otron/meme_db.py index 90da643..cda27ce 100644 --- a/meme_otron/meme_db.py +++ b/meme_otron/meme_db.py @@ -1,10 +1,11 @@ import json import logging +import os.path as path from .types import Pos, Text, Meme from . import utils -DATA_FILE = "../memes.json" +DATA_FILE = utils.relative_path(__file__, "..", "memes.json") DATA = {} ALIASES = {} @@ -117,7 +118,7 @@ def load_text(j, raw_text): """ if not (isinstance(raw_text, dict)): raise TypeError(f"root is not a dict") - text = Text(f"text {j+1}") + text = Text(f"text {j + 1}") if "font" in raw_text: if not (isinstance(raw_text["font"], str)): raise TypeError(f"'font' is not a str") diff --git a/meme_otron/utils.py b/meme_otron/utils.py index edace2a..3003bcc 100644 --- a/meme_otron/utils.py +++ b/meme_otron/utils.py @@ -1,4 +1,9 @@ import re +import os.path as path + + +def relative_path(file, *args): + return path.realpath(path.join(path.dirname(path.realpath(file)), *args)) def read_key_safe(d, k, default=None):