From 94f15c0ba73ea14770cb74c8dd94448402318c6c Mon Sep 17 00:00:00 2001 From: Anon E Mouse Date: Wed, 10 Jan 2024 15:16:09 -0500 Subject: [PATCH 1/3] Add qrconfirm field. --- README.rst | 4 ++-- whatapi/whatapi.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index ac514bc..0b34011 100644 --- a/README.rst +++ b/README.rst @@ -16,7 +16,7 @@ Example usage: :: >>> import whatapi - >>> apihandle = whatapi.WhatAPI(username='me', password='secret') + >>> apihandle = whatapi.WhatAPI(username='me', password='secret', two_factor=None) >>> apihandle.request("browse", searchstr="Talulah Gosh") ... >>> apihandle.get_torrent(1234567) @@ -28,7 +28,7 @@ To use another tracker: :: >>> import whatapi - >>> apihandle = whatapi.WhatAPI(username='me', password='secret', + >>> apihandle = whatapi.WhatAPI(username='me', password='secret', two_factor='actfast', server='https://passtheheadphones.me') >>> apihandle.request("browse", searchstr="The Beatles") ... diff --git a/whatapi/whatapi.py b/whatapi/whatapi.py index 22d5dcd..a55567f 100644 --- a/whatapi/whatapi.py +++ b/whatapi/whatapi.py @@ -21,7 +21,7 @@ class RequestException(Exception): class WhatAPI: def __init__(self, config_file=None, username=None, password=None, cookies=None, - server="https://ssl.what.cd", throttler=None): + server="https://ssl.what.cd", throttler=None, two_factor=None): self.session = requests.Session() self.session.headers = headers self.authkey = None @@ -33,9 +33,11 @@ def __init__(self, config_file=None, username=None, password=None, cookies=None, config.read(config_file) self.username = config.get('login', 'username') self.password = config.get('login', 'password') + self.two_factor = config.get('login', 'two_factor') else: self.username = username self.password = password + self.two_factor = two_factor if cookies: self.session.cookies = cookies try: @@ -59,6 +61,9 @@ def _login(self): 'keeplogged': 1, 'login': 'Login' } + if self.two_factor is not None: + data['qrcode_confirm'] = self.two_factor + r = self.session.post(loginpage, data=data, allow_redirects=False) if r.status_code != 302: raise LoginException @@ -120,4 +125,4 @@ def throttle_request(self): if sleep_time > 0: time.sleep(sleep_time) self.request_times = self.request_times[1:] - self.request_times.append(request_time) \ No newline at end of file + self.request_times.append(request_time) From 805e1ea4eca40242a3f4451d752234e8f27358c0 Mon Sep 17 00:00:00 2001 From: Anon E Mouse Date: Wed, 10 Jan 2024 15:35:03 -0500 Subject: [PATCH 2/3] Allow arbitrary updated payload. --- whatapi/whatapi.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/whatapi/whatapi.py b/whatapi/whatapi.py index a55567f..60211ca 100644 --- a/whatapi/whatapi.py +++ b/whatapi/whatapi.py @@ -21,23 +21,22 @@ class RequestException(Exception): class WhatAPI: def __init__(self, config_file=None, username=None, password=None, cookies=None, - server="https://ssl.what.cd", throttler=None, two_factor=None): + server="https://ssl.what.cd", throttler=None, update_payload={}): self.session = requests.Session() self.session.headers = headers self.authkey = None self.passkey = None self.server = server self.throttler = Throttler(5, 10) if throttler is None else throttler + self.update_payload = update_payload if config_file: config = ConfigParser() config.read(config_file) self.username = config.get('login', 'username') self.password = config.get('login', 'password') - self.two_factor = config.get('login', 'two_factor') else: self.username = username self.password = password - self.two_factor = two_factor if cookies: self.session.cookies = cookies try: @@ -61,8 +60,7 @@ def _login(self): 'keeplogged': 1, 'login': 'Login' } - if self.two_factor is not None: - data['qrcode_confirm'] = self.two_factor + data.update(self.update_payload) r = self.session.post(loginpage, data=data, allow_redirects=False) if r.status_code != 302: From f07108e9f430577ccd9a44d9d74be8c24152c017 Mon Sep 17 00:00:00 2001 From: Anon E Mouse Date: Wed, 10 Jan 2024 15:39:21 -0500 Subject: [PATCH 3/3] update readme. --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 0b34011..1bd1ef2 100644 --- a/README.rst +++ b/README.rst @@ -16,7 +16,7 @@ Example usage: :: >>> import whatapi - >>> apihandle = whatapi.WhatAPI(username='me', password='secret', two_factor=None) + >>> apihandle = whatapi.WhatAPI(username='me', password='secret', update_payload={'qr_confirm': 'code'}) >>> apihandle.request("browse", searchstr="Talulah Gosh") ... >>> apihandle.get_torrent(1234567) @@ -28,7 +28,7 @@ To use another tracker: :: >>> import whatapi - >>> apihandle = whatapi.WhatAPI(username='me', password='secret', two_factor='actfast', + >>> apihandle = whatapi.WhatAPI(username='me', password='secret', server='https://passtheheadphones.me') >>> apihandle.request("browse", searchstr="The Beatles") ...