-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstartup.py
41 lines (31 loc) · 1.04 KB
/
startup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import asyncio
import logging
from os import getenv
from dotenv import load_dotenv
from aiogram import Bot
from vk.methods import get_credentials, get_user_credentials
from main import main
load_dotenv()
logging.basicConfig(filename="../sferum_in.log", encoding="utf-8", level=logging.INFO, datefmt='%m/%d/%Y %I:%M:%S %p')
tg_chat_id = getenv("TG_CHAT_ID")
tg_topic_id = int(getenv("TG_TOPIC_ID", default=0))
vk_chat_ids = getenv("VK_CHAT_ID")
bot_token = getenv("BOT_TOKEN")
cookie = getenv("AUTH_COOKIE")
user = get_user_credentials(cookie)
access_token = user.access_token
creds = get_credentials(access_token)
loop = asyncio.get_event_loop()
try:
bot = Bot(bot_token)
task2 = loop.create_task(main(creds.server, creds.key, creds.ts, tg_chat_id, vk_chat_ids, access_token, cookie, creds.pts, bot, tg_topic_id))
logging.info("Loop starting")
loop.run_forever()
except KeyboardInterrupt:
pass
except Exception as e:
logging.exception(e)
finally:
logging.info("Closing loop...")
loop.close()
logging.info("Loop closed")