-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
39 lines (29 loc) · 1006 Bytes
/
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
from ctypes import sizeof
import os
from dotenv import load_dotenv
from crontab import CronTab
from twitchAPI.twitch import Twitch
import schedule
import time
from service.twitch_service import get_streams
from service.twitter_service import tweet_stream
print('Starting Bot...')
load_dotenv()
twitch = Twitch(os.environ['CLIENT_ID'], os.environ['CLIENT_SECRET'])
streams_map = dict()
streams_map = {}
def job():
streams = get_streams()
for stream in streams:
if stream['user_name'] not in streams_map or streams_map[stream['user_name']] != stream['started_at']:
try:
streams_map[stream['user_name']] = stream['started_at']
tweet_stream(stream)
print(f'Twitting {stream["user_name"]} stream...')
except Exception as e:
print(f'Couldnt Twit {stream["user_name"]} stream...')
schedule.every(30).seconds.do(job)
print('Bot Scheduled...')
while True:
schedule.run_pending()
time.sleep(1)