-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (50 loc) · 2.07 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import asyncio
import importlib.util
import logging
import os
from dotenv import load_dotenv
from clients.lyrics_genius_client import LyricsGeniusClient
from clients.yandex_music_client import YandexMusicClient
from services.random_quote import RandomQuote
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format="[ # RandomQuote ] %(message)s",
)
def load_addons(addons_folder="Addons"):
addons = {}
for filename in os.listdir(addons_folder):
if filename.endswith(".py"):
module_name = filename[:-3]
spec = importlib.util.spec_from_file_location(
module_name, os.path.join(addons_folder, filename)
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
addons[module_name] = module
return addons
async def main():
logging.info("Запускаем RandomQuote by xdearboy...")
yandex_token = os.getenv("YANDEX_TOKEN")
genius_access_token = os.getenv("GENIUS_ACCESS_TOKEN")
enable_lyrics_to_tg = os.getenv("ENABLE_LYRICS_TO_TG", "false").lower() == "true"
yandex_client = YandexMusicClient(yandex_token)
genius_client = LyricsGeniusClient(genius_access_token)
random_quote = RandomQuote(yandex_client, genius_client)
random_quote.generate_quote()
addons = load_addons()
if enable_lyrics_to_tg and "lyrics_to_tg" in addons:
api_id = int(os.getenv("TELEGRAM_API_ID"))
api_hash = os.getenv("TELEGRAM_API_HASH")
phone_number = os.getenv("TELEGRAM_PHONE_NUMBER")
with open("random_lyrics.txt", "r", encoding="utf-8") as file:
lines = file.readlines()
lyrics = " ".join(lines[2:])
if lyrics:
await addons["lyrics_to_tg"].update_profile_description(
lyrics, api_id, api_hash, phone_number
)
else:
print("[ # RandomQuote ] Текст не найден, не отправляем в Telegram.")
if __name__ == "__main__":
asyncio.run(main())