diff options
author | Vee9ahd1 <[email protected]> | 2019-05-12 01:29:05 -0400 |
---|---|---|
committer | Vee9ahd1 <[email protected]> | 2019-05-12 01:29:05 -0400 |
commit | 2e27eb73344d691b657f72c8e794f81ce47036c6 (patch) | |
tree | fafe6255167c74131f03e2a80b105278c28af30d /gantools/ganbreeder.py | |
parent | 560f86d452277084a1be04fbc4c0e8c5f1206ff5 (diff) |
implemented most of the basic functionality from the prototype script and created some messy tests
Diffstat (limited to 'gantools/ganbreeder.py')
-rw-r--r-- | gantools/ganbreeder.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gantools/ganbreeder.py b/gantools/ganbreeder.py new file mode 100644 index 0000000..2e7f946 --- /dev/null +++ b/gantools/ganbreeder.py @@ -0,0 +1,45 @@ +# client functions for interacting with the ganbreeder api +import requests +import json + +def login(username, password): + def get_sid(): + url = 'https://ganbreeder.app/login' + r = requests.get(url) + r.raise_for_status() + for c in r.cookies: + if c.name == 'connect.sid': # find the right cookie + print('Session ID: '+str(c.value)) + return c.value + + def login_auth(sid, username, password): + url = 'https://ganbreeder.app/login' + headers = { + 'Content-Type': 'application/json', + } + cookies = { + 'connect.sid': sid + } + payload = { + 'email': username, + 'password': password + } + r = requests.post(url, headers=headers, cookies=cookies, data=json.dumps(payload)) + if not r.ok: + print('Authentication failed') + r.raise_for_status() + print('Authenticated') + + sid = get_sid() + login_auth(sid, username, password) + return sid + +def get_info(sid, key): + if sid == '': + raise Exception('Cannot get info; session ID not defined. Be sure to login() first.') + cookies = { + 'connect.sid': sid + } + r = requests.get('http://ganbreeder.app/info?k='+str(key), cookies=cookies) + r.raise_for_status() + return(r.json()) |