From 1c6ca4d73a0a8da95b2873f70d99ccc4c9a676b2 Mon Sep 17 00:00:00 2001 From: Mantou-9487 Date: Tue, 16 Jul 2024 16:06:30 +0800 Subject: [PATCH] refactor: request method use session --- tystream/twitch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tystream/twitch.py b/tystream/twitch.py index 9372212..967a836 100644 --- a/tystream/twitch.py +++ b/tystream/twitch.py @@ -54,7 +54,7 @@ def get_user(self, streamer_name: str) -> TwitchUserData: """ headers = self._get_headers() - user = requests.get( + user = self.session.get( "https://api.twitch.tv/helix/users?login=" + streamer_name, headers=headers, timeout=10 @@ -83,7 +83,7 @@ def check_stream_live(self, streamer_name: str) -> TwitchStreamData | bool: user = self.get_user(streamer_name) - stream = requests.get( + stream = self.session.get( "https://api.twitch.tv/helix/streams?user_login=" + streamer_name, headers=headers, timeout=10 @@ -96,6 +96,7 @@ def check_stream_live(self, streamer_name: str) -> TwitchStreamData | bool: self.logger.log(25, "%s is live!", streamer_name) return TwitchStreamData(**stream_data["data"][0], user=user) + def get_stream_vod(self, streamer_name: str) -> TwitchVODData: """ Retrieve the latest Twitch Stream VOD data. @@ -118,7 +119,7 @@ def get_stream_vod(self, streamer_name: str) -> TwitchVODData: user = self.get_user(streamer_name) - vod = requests.get( + vod = self.session.get( f"https://api.twitch.tv/helix/videos?user_id={user.id}&type=archive", headers=headers, timeout=10