Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Example usage:
::

>>> import whatapi
>>> apihandle = whatapi.WhatAPI(username='me', password='secret')
>>> apihandle = whatapi.WhatAPI(username='me', password='secret', update_payload={'qr_confirm': 'code'})
>>> apihandle.request("browse", searchstr="Talulah Gosh")
...
>>> apihandle.get_torrent(1234567)
Expand Down
7 changes: 5 additions & 2 deletions whatapi/whatapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ 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, 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)
Expand Down Expand Up @@ -59,6 +60,8 @@ def _login(self):
'keeplogged': 1,
'login': 'Login'
}
data.update(self.update_payload)

r = self.session.post(loginpage, data=data, allow_redirects=False)
if r.status_code != 302:
raise LoginException
Expand Down Expand Up @@ -120,4 +123,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)
self.request_times.append(request_time)