From ebe14e50acb7629fe3e6128fc61ec47c2168eeb3 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Tue, 10 May 2022 10:28:51 -0400 Subject: [PATCH 1/2] Add search channels endpoint --- twitch/helix/api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/twitch/helix/api.py b/twitch/helix/api.py index 37e436b..0bb5f2a 100644 --- a/twitch/helix/api.py +++ b/twitch/helix/api.py @@ -21,6 +21,7 @@ Tag, User, Video, + Channel ) @@ -374,3 +375,23 @@ def get_tags(self, after=None, page_size=20, tag_ids=None): resource=Tag, params=params, ) + + def search_channels(self, query, after=None, page_size=20, live_only=False): + """https://dev.twitch.tv/docs/api/reference#search-channels""" + if page_size > 100: + raise TwitchAttributeException('Maximum number of objects to return is 100') + + params = { + 'query': query, + 'after': after, + 'first': page_size, + 'live_only': live_only + } + + return APICursor( + client_id=self._client_id, + oauth_token=self._oauth_token, + path='search/channels', + resource=Channel, + params=params, + ) \ No newline at end of file From a3a7777a3a7e45df14ebb690e4ef0de00992c7cb Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Tue, 10 May 2022 10:29:52 -0400 Subject: [PATCH 2/2] Handle empty datetime Offline channels from the "search_channels" endpoint return an empty string --- twitch/resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitch/resources.py b/twitch/resources.py index 456aa0a..c9d4fbb 100644 --- a/twitch/resources.py +++ b/twitch/resources.py @@ -68,7 +68,7 @@ def refresh_from(self, values): class _DateTime(object): @classmethod def construct_from(cls, value): - if value is None: + if value is None or value == '': return None try: dt = datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ")