From 1053dfad9a7c0f38b1d704636f4cc108a3bf4432 Mon Sep 17 00:00:00 2001 From: alexvanin Date: Sat, 28 Mar 2020 18:40:36 +0300 Subject: [PATCH] api: Save any non empty results during game search and use char escaping in game search --- main.py | 2 +- twitch.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index bb37fbd..d16578d 100755 --- a/main.py +++ b/main.py @@ -68,7 +68,7 @@ class FleastServer(object): if game == "IRL": data = self.client.get_irl_live_streams_v6(lang) else: - data = self.client.get_live_streams(game.replace(' ', '%20').replace('&', '%26'), lang) + data = self.client.get_live_streams(game, lang) if data is None: return 'Internal Error
Tell me more at ' \ diff --git a/twitch.py b/twitch.py index ba46a8b..e867920 100644 --- a/twitch.py +++ b/twitch.py @@ -2,6 +2,7 @@ import cherrypy import requests import threading import time +from urllib.parse import quote class TwitchClient: @@ -148,15 +149,15 @@ class TwitchClient: https://dev.twitch.tv/docs/v5/reference/search/#search-streams """ result = {'_total': 0, 'streams': []} - game_id = self.get_game_id_v6(name) - if game_id[0] is None: + game_id = self.get_game_id_v6(quote(name)) + if game_id is None: return result header, base = self.get_base('v6') init_q_template = "{}/streams?language={}&first={}&game_id={}" q_template = "{}/streams?language={}&first={}&after={}&game_id={}" - data = self.do_q(init_q_template.format(base, lang, 100, game_id[0]), header) + result['streams'].extend(data['data']) while len(data.get('data', [])) > 0.8*100: result['streams'].extend(data['data']) data = self.do_q(q_template.format(base, lang, 100, data['pagination']['cursor'], game_id[0]), header) @@ -176,6 +177,7 @@ class TwitchClient: result = {'_total': 0, 'streams': []} data = self.do_q(init_q_template.format(base, lang, 100, game_id), header) + result['streams'].extend(data['data']) while len(data.get('data', [])) > 0.8*100: result['streams'].extend(data['data']) data = self.do_q(q_template.format(base, lang, 100, data['pagination']['cursor'], game_id), header)