-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (47 loc) · 1.65 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
import asyncio
import logging
import random
import json
import config
from sticker_price_updater import StickerPriceUpdater
from buff_parser import BuffParser
from notifying import BotNotifier
import message_handlers
def read_json(file_name: str):
with open(file_name, 'r') as file:
return json.load(file)
def write_json(file_name: str, data):
with open(file_name, 'w') as file:
json.dump(data, file, ensure_ascii=False, indent=4)
async def sticker_price_updater_task(stickers):
sticker_updater = StickerPriceUpdater(stickers)
logging.getLogger("StickerPriceUpdater").setLevel(logging.WARNING)
try:
while True:
await sticker_updater.fetch_sticker_prices()
write_json('data\\stickers.json', stickers)
await asyncio.sleep(7200)
finally:
write_json('data\\stickers.json', stickers)
async def buff_parser_task(stickers):
with open('data\\itemids.txt', 'r') as file:
items = [line.strip().split(';') for line in file]
random.shuffle(items)
users = [404404154, 497136005]
notifier = BotNotifier(config.bot, users)
buff_parser = BuffParser(items, stickers, notifier)
while True:
await buff_parser.fetch_main_data()
async def main():
stickers = read_json('data\\stickers.json')
loop = asyncio.get_event_loop()
loop.create_task(sticker_price_updater_task(stickers))
loop.create_task(buff_parser_task(stickers))
if __name__ == '__main__':
loop = asyncio.new_event_loop()
loop.create_task(main())
try:
loop.run_forever()
finally:
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()