From 60a374d9ec79ec6b158faa2c7bb2b8eca828093d Mon Sep 17 00:00:00 2001 From: Michelle Date: Thu, 19 Feb 2026 15:02:18 +0100 Subject: [PATCH] Add Dockerfile and more print statements for logs --- Dockerfile | 8 ++++++++ main.py | 12 +++++++++--- requirements.txt | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cce781 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.13.12-slim-trixie + +ENV PATH=/usr/local/bin:$PATH +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY . . +CMD ["python", "-u", "main.py"] \ No newline at end of file diff --git a/main.py b/main.py index 6ebc17d..d6f662a 100644 --- a/main.py +++ b/main.py @@ -30,10 +30,12 @@ async def get_latest_post(subreddit): if response.status_code == 200: try: data = response.json() + print(f"Fetched data from Reddit: {data}") if data["data"]["children"]: for child in data["data"]["children"]: post = child["data"] if post.get("post_hint") == "image" and post.get("url", "").endswith((".jpg", ".png", ".jpeg", ".gif")): + print(f"Found image post: {post['title']} - {post['url']}") return post["title"], post["url"] except (KeyError, json.JSONDecodeError): return None, None @@ -49,7 +51,7 @@ async def setChannel(message): guild_id = getattr(channel, "guild_id", None) or getattr(channel, "guild", {}).get("id", None) print(f"Setting channel to {channel_id} for guild {guild_id}") try: - con = sqlite3.connect('ich_iel-bot.db') + con = sqlite3.connect('data/ich_iel-bot.db') con = con.cursor() con.execute("CREATE TABLE IF NOT EXISTS channels (guild_id INTEGER PRIMARY KEY, channel_id INTEGER)") con.execute("INSERT OR REPLACE INTO channels (guild_id, channel_id) VALUES (?, ?)", (guild_id, channel_id)) @@ -71,7 +73,7 @@ async def post_reddit(): title, image_url = await get_latest_post(subreddit) if title and image_url: try: - con = sqlite3.connect('ich_iel-bot.db') # i like sqlite + con = sqlite3.connect('data/ich_iel-bot.db') # i like sqlite con = con.cursor() con.execute("SELECT guild_id, channel_id FROM channels") rows = con.fetchall() @@ -91,5 +93,9 @@ async def post_reddit(): print(f"Database error: {e}") if __name__ == "__main__": + print("Starting bot...") TOKEN = os.getenv("FLUXER_TOKEN") - bot.run(TOKEN) \ No newline at end of file + if not TOKEN: + print("Error: FLUXER_TOKEN not found in environment variables") + else: + bot.run(TOKEN) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5cfab1a..8b2cade 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fluxer.py==0.2.0 +fluxer.py requests asyncio dotenv \ No newline at end of file