This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmain.py
56 lines (47 loc) · 1.88 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
import sys
import threading
from claim_bonus import load_channel_points_context
from exceptions import StreamerDoesNotExistException
from login import check_login
from pubsub import listen_for_channel_points
from twitch_data import set_streamer_logins, get_channel_id, do_for_each_streamer
from watch_minute import send_minute_watched_events
def main():
if not check_login():
print("Login failed.")
return
streamer_logins = read_streamer_logins()
if not streamer_logins:
print("You have to specify at least one streamer!")
return
set_streamer_logins(streamer_logins)
do_for_each_streamer(load_channel_points_context)
start_watching()
listen_for_channel_points()
# Read streamer logins from command-line arguments, if possible. Otherwise, prompt user input.
def read_streamer_logins():
user_input = []
if len(sys.argv) <= 1: # no command-line args (the first is always source file name)
print("Enter the streamer name (or several separated by commas). More important streamers go first.")
twitch_streamers = input("Streamer names: ")
user_input = twitch_streamers.split(",")
else:
for i in range(1, len(sys.argv)):
user_input += sys.argv[i].split(",")
streamer_logins = []
for streamer_login in user_input:
streamer_login = streamer_login.strip()
if not streamer_login:
continue
try:
get_channel_id(streamer_login)
except StreamerDoesNotExistException:
print(f"Streamer {streamer_login} does not exist")
else:
streamer_logins.append(streamer_login)
return streamer_logins
def start_watching():
minute_watcher_thread = threading.Thread(target=send_minute_watched_events)
minute_watcher_thread.start()
if __name__ == "__main__":
main()