From 9b992cce9d187d136512e257f11a3895c842a960 Mon Sep 17 00:00:00 2001 From: Date: Mon, 9 Oct 2017 01:17:12 +0300 Subject: [PATCH] Decided to work with APIv5 later --- src/main.py | 6 +++--- src/twitch.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index 5971919..159b5f9 100755 --- a/src/main.py +++ b/src/main.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from twitch import TwitchClient + import json def main(): @@ -9,9 +10,8 @@ def main(): twitch_token = reader.read().strip() client = TwitchClient(twitch_token) - streams = client.raw_query_v6('streams?game_id=%s&first=100&language=ru&type=live' % client.get_game_id('IRL')[0]) - for i in streams['data']: - print(i['title']) + r = client.raw_query_v5('streams/?game=IRL&language=ru&limit=2') + print(json.dumps(r, indent=4)) if __name__ == '__main__': diff --git a/src/twitch.py b/src/twitch.py index e467fb7..7358c91 100644 --- a/src/twitch.py +++ b/src/twitch.py @@ -32,10 +32,14 @@ class TwitchClient: header, base = self.get_base('v6') return self.do_q(base+q, header) + def raw_query_v5(self, q): + header, base = self.get_base('v5') + return self.do_q(base+q, header) + # Returns (ID, GAMENAME) or None def get_game_id(self, name): header, base = self.get_base('v5') r = self.do_q('%s/search/games?query=%s' % (base, name), header) if r.get('games', None): return (r['games'][0]['_id'], r['games'][0]['name']) return None - +