-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch-following.py
35 lines (27 loc) · 1.04 KB
/
twitch-following.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
import logging
import time
import winsound
from urllib.error import URLError
from genutility.datetime import now
from genutility.twitch import TwitchAPI
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("username")
parser.add_argument("clientid")
parser.add_argument("--interval", type=int, default=120)
args = parser.parse_args()
watcher = TwitchAPI(args.clientid, username=args.username).watcher()
def notify_started(user_id, name, title):
print("{} started streaming '{}' at {}".format(name, title, now().isoformat(" ")))
winsound.Beep(880, 1000) # frequency, duration
def notify_stopped(user_id, name):
print("{} stopped streaming at {}".format(name, now().isoformat(" ")))
while True:
try:
watcher.watch(notify_started, notify_stopped)
except URLError:
logging.warning("Internet error")
except ValueError:
logging.warning("Wrong data")
time.sleep(args.interval)