From 85f1e3d54e7c028c80739128e710f5ae8d82b8fd Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Wed, 22 Mar 2023 19:10:44 +0300 Subject: [PATCH] use env for params --- .gitignore | 1 + example.env | 2 ++ main.py | 12 ++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 example.env diff --git a/.gitignore b/.gitignore index aa1a858..e43fd64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea *.py[oc] +.env diff --git a/example.env b/example.env new file mode 100644 index 0000000..707717d --- /dev/null +++ b/example.env @@ -0,0 +1,2 @@ +BOT_TOKEN=450146961:asd +SEND_CHAT=9893249151 diff --git a/main.py b/main.py index 12f59a8..58df2ed 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,22 @@ import asyncio +import logging +import os import redis.asyncio as aioredis -import logging from aiogram import Bot, Dispatcher from aiogram.types import Message from aiogram.utils import executor +import dotenv from e621 import E621 +dotenv.load_dotenv('.env') + redis = aioredis.from_url('redis://localhost') e621 = E621() logging.basicConfig(level=logging.INFO) -bot = Bot(token='450146961:AAFqwPcXuWXaYP8j8sE_rYgp_dAsk9YWf7I') +bot = Bot(token=os.environ['BOT_TOKEN']) dp = Dispatcher(bot) @@ -34,14 +38,14 @@ async def check_updates(): f'Character: {" ".join(post.tags.character)}\n\n' \ f'https://e621.net/posts/{post.id}' if post.file.ext == 'webm': - await bot.send_video(98934915, + await bot.send_video(int(os.environ['SEND_CHAT']), post.file.url, width=post.file.width, height=post.file.height, thumb=post.preview.url, caption=caption) else: - await bot.send_photo(98934915, + await bot.send_photo(int(os.environ['SEND_CHAT']), post.file.url, caption=caption) await redis.sadd('e621:sent', post.id)