|
|
@ -46,6 +46,21 @@ class Twitch(object):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_stream_info(self, user_id):
|
|
|
|
|
|
|
|
def request():
|
|
|
|
|
|
|
|
url = '{0}/streams/{1}'.format(self.api_url, user_id)
|
|
|
|
|
|
|
|
params = dict(client_id=self.client_id)
|
|
|
|
|
|
|
|
r = requests.get(url, params=params)
|
|
|
|
|
|
|
|
r.raise_for_status()
|
|
|
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
data = request()
|
|
|
|
|
|
|
|
if data['stream'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
|
|
|
|
id=int(data['stream']['_id']),
|
|
|
|
|
|
|
|
game=data['stream']['game'],
|
|
|
|
|
|
|
|
viewers=int(data['stream']['viewers']))
|
|
|
|
|
|
|
|
|
|
|
|
def get_messages(self, user_id, since):
|
|
|
|
def get_messages(self, user_id, since):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
videos = self._get_videos(user_id)
|
|
|
|
videos = self._get_videos(user_id)
|
|
|
@ -61,3 +76,11 @@ class Twitch(object):
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_stream_info(self, user_id):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
return self._get_stream_info(user_id)
|
|
|
|
|
|
|
|
except requests.exceptions.HTTPError as e:
|
|
|
|
|
|
|
|
if self.log:
|
|
|
|
|
|
|
|
self.log.error('Failed to get stream info: %s', str(e))
|
|
|
|
|
|
|
|
return None
|
|
|
|