-
Notifications
You must be signed in to change notification settings - Fork 2
/
TwitchAPI.py
24 lines (20 loc) · 859 Bytes
/
TwitchAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
from time import sleep
import pprint
def check_for_stream(user):
pp = pprint.PrettyPrinter(indent=1)
a = requests.get("https://api.twitch.tv/kraken/users/{}/follows/channels".format(user))
a = a.json()["follows"]
channels = {}
for channel in a:
channels[channel["channel"]["name"]] = [channel["channel"]["name"], channel["channel"]["display_name"], channel["channel"]["url"]]
to_return = []
for channel in channels:
r = requests.get("https://api.twitch.tv/kraken/streams/{}".format(channels[channel][0])).json()
if "stream" in r:
if r["stream"] != None:
to_return.append([channels[channel][1], r["stream"]["game"], r["stream"]["channel"]["status"], channels[channel][2]])
else:
print(channel)
pp.pprint(r)
return to_return