Skip to content
This repository was archived by the owner on Mar 3, 2018. It is now read-only.

Commit 8cf62b1

Browse files
author
Rolandas Barysas
committed
fixed error when twitch username does not exist
1 parent 91736cd commit 8cf62b1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

run.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def fetch_followed_channels(self, username):
2121
self.f = urllib.urlopen("https://api.twitch.tv/kraken/users/{0}/follows/channels?direction=DESC&limit=100&offset=0&sortby=created_at".format(username))
2222
self.data = json.loads(self.f.read())
2323

24+
# Return 404 if user does not exist
25+
try:
26+
if (self.data["status"] == 404):
27+
return 404
28+
except KeyError:
29+
pass
30+
2431
self.pages = (self.data['_total'] - 1) / 100
2532
for page in range(0, self.pages + 1):
2633
if page != 0:
@@ -212,8 +219,13 @@ def refresh_streams(self):
212219

213220
# Create twitch instance and fetch followed channels.
214221
self.tw = Twitch()
215-
216222
self.followed_channels = self.tw.fetch_followed_channels(self.settings.get_string("twitch-username"))
223+
224+
# Does user exist?
225+
if self.followed_channels == 404:
226+
GLib.idle_add(self.abort_refresh, "Cannot retrieve followed channels from Twitch.tv", "User does not exist.")
227+
return
228+
217229
if self.followed_channels == None:
218230
GLib.idle_add(self.abort_refresh, "Cannot retrieve channel list from Twitch.tv", "Retrying in {0} minutes...".format(self.settings.get_int("refresh-interval")))
219231
return

0 commit comments

Comments
 (0)