Change Twitch user_id to channel_id

master
Nikola Forró 6 years ago
parent baa70a1a50
commit a89ac4375f

@ -60,11 +60,11 @@ class Commands(object):
since = quote['date']
api_url = self.config['Twitch'].get('api_url')
client_id = self.config['Twitch'].get('client_id')
user_id = self.config['Twitch'].getint('target_user_id')
channel_id = self.config['Twitch'].getint('channel_id')
since = dateutil.parser.parse(since).date()
twitch = Twitch(api_url, client_id)
try:
return twitch.get_messages(user_id, since)
return twitch.get_messages(channel_id, since)
except TwitchError as e:
raise CommandError(e)

@ -11,9 +11,9 @@ class Twitch(object):
self.api_url = api_url
self.client_id = client_id
def _get_videos(self, user_id):
def _get_videos(self, channel_id):
def request(offset, limit):
url = '{0}/channels/{1}/videos'.format(self.api_url, user_id)
url = '{0}/channels/{1}/videos'.format(self.api_url, channel_id)
params = dict(client_id=self.client_id, offset=offset, limit=limit)
r = requests.get(url, params=params)
r.raise_for_status()
@ -49,9 +49,9 @@ class Twitch(object):
break
return result
def _get_stream_info(self, user_id):
def _get_stream_info(self, channel_id):
def request():
url = '{0}/streams/{1}'.format(self.api_url, user_id)
url = '{0}/streams/{1}'.format(self.api_url, channel_id)
params = dict(client_id=self.client_id)
r = requests.get(url, params=params)
r.raise_for_status()
@ -64,9 +64,9 @@ class Twitch(object):
game=data['stream']['game'],
viewers=int(data['stream']['viewers']))
def get_messages(self, user_id, since):
def get_messages(self, channel_id, since):
try:
videos = self._get_videos(user_id)
videos = self._get_videos(channel_id)
result = []
for video in [v for v in videos if v['date'] >= since]:
comments = self._get_comments(video['id'])
@ -76,8 +76,8 @@ class Twitch(object):
else:
return result
def get_stream_info(self, user_id):
def get_stream_info(self, channel_id):
try:
return self._get_stream_info(user_id)
return self._get_stream_info(channel_id)
except requests.exceptions.HTTPError as e:
raise TwitchError('Failed to get stream info: {0}'.format(e))

@ -12,7 +12,7 @@ api_url = https://api.twitch.tv/v5
client_id = __TWITCH_CLIENT_ID__
token = oauth:__TWITCH_OAUTH_TOKEN__
# lilialil
target_user_id = 92737529
channel_id = 92737529
# nikola_f
master_user_id = 210957066

Loading…
Cancel
Save