From 864ce1cb80f7219c8200db61c8226ddfb57402b0 Mon Sep 17 00:00:00 2001 From: Kirill Gavrilov Date: Sun, 12 Aug 2018 17:13:34 +0300 Subject: [PATCH 1/2] Fixed username parsing Fixes #105 --- pyperi/pyperi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperi/pyperi.py b/pyperi/pyperi.py index f68ba54..a8a40b0 100644 --- a/pyperi/pyperi.py +++ b/pyperi/pyperi.py @@ -121,7 +121,7 @@ def get_web_public_user_session_tokens(self, user_id=None, username=None): 'broadcastHistory', 'serviceToken', 'thumbnailPlaylist' ] - out = {'user_id': data_store['Tracking']['userId']} + out = {'user_id': data_store['UserCache']['usernames'][username.lower()]} for token_name in token_names: out[token_name] = public_tokens[token_name]['token']['session_id'] From 5f04fe01202a9e7dc05788c3c2359e3bb9740b23 Mon Sep 17 00:00:00 2001 From: Tony Cebzanov Date: Fri, 18 Jan 2019 17:42:13 -0500 Subject: [PATCH 2/2] Allow caller to supply their own session object. * Add a constructor to the Peri() object that takes a `session` parameter. If supplied, this session object will be used instead of creating a new one. My use case is for HTTP proxy support, but presumably the caller could change the user agent in some other way if they wanted to. If no session param is supplied, one is created, as before. --- pyperi/pyperi.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyperi/pyperi.py b/pyperi/pyperi.py index a8a40b0..dfeef03 100644 --- a/pyperi/pyperi.py +++ b/pyperi/pyperi.py @@ -17,6 +17,14 @@ class Peri(object): PERISCOPE_API_BASE_URL = 'https://api.periscope.tv/api/v2' PERISCOPE_WEB_BASE_URL = 'https://www.periscope.tv' + def __init__(self, session=None): + """ + Constructor. If a `session` is passed, it will be used to retrieve + URLs. This should be a `requests.Session` object, or something like it. + If no `session` is passed, one will be created for you. + """ + self.session = session if session else requests.Session() + def request_api(self, endpoint, **params): """ Make a request against the Periscope API and return the result. @@ -27,7 +35,7 @@ def request_api(self, endpoint, **params): url = self._create_api_request_url(endpoint, **params) try: - r = requests.get(url) + r = self.session.get(url) except requests.exceptions.ConnectionError as e: raise PyPeriConnectionError(e) @@ -186,7 +194,7 @@ def _get_web_data_store(self, url): return None. """ try: - r = requests.get(url) + r = self.session.get(url) except requests.exceptions.ConnectionError as e: raise PyPeriConnectionError(e)