From f009aa0ca0d0b207c12c9a564e6b2e9ec1959eaa Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Thu, 21 Jan 2016 11:18:51 -0500 Subject: [PATCH] Use new inara.py library instead of having 2 versions of the code. --- .gitmodules | 3 +++ inara | 1 + inara.py | 72 ------------------------------------------------- update_inara.py | 11 +++----- 4 files changed, 8 insertions(+), 79 deletions(-) create mode 160000 inara delete mode 100644 inara.py diff --git a/.gitmodules b/.gitmodules index e13794f..a696733 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "EDMarketConnector"] path = edmc url = https://github.com/Marginal/EDMarketConnector.git +[submodule "inara"] + path = inara + url = https://github.com/annabunches/inara.py.git diff --git a/inara b/inara new file mode 160000 index 0000000..010ff37 --- /dev/null +++ b/inara @@ -0,0 +1 @@ +Subproject commit 010ff377e5b4af772f2dbe2736608cee4f04f58a diff --git a/inara.py b/inara.py deleted file mode 100644 index b5250bf..0000000 --- a/inara.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Creates connections to inara.cz to retrieve and update player info. - -import requests -import sys - -URL_BASE = "http://inara.cz/" -URL_LOGIN = URL_BASE -URL_CMDR = URL_BASE + "cmdr/" - -class ServerError(Exception): - pass - -class CredentialsError(Exception): - pass - -class Session(requests.Session): - def __init__(self): - requests.Session.__init__(self) - - - def inara_login(self, username, password): - if (not username or not password): - raise CredentialsError() - - data = { - "loginid": username, - "loginpass": password, - "formact": "ENT_LOGIN", - "location": "intro" - } - - self._inara_handled_request(self.post, URL_LOGIN, data=data) - - - def inara_update_credits(self, credits): - data = { - "location": "cmdr", - "formact": "USER_CREDITS_SET", - "playercredits": credits, - "playercreditsassets": None, - "oass": 48126920, - } - self._inara_handled_request(self.post, URL_CMDR, data=data) - - - def inara_update_location(self, location): - data = { - 'formact': 'USER_LOCATION_SET', - 'playercurloc': location - } - self._inara_handled_request(self.post, URL_CMDR, data=data) - - - def _inara_handled_request(self, func, url, data=None): - r = func(url, data=data) - r.raise_for_status() - - def _inara_dump(self, r): - print "Request:" - print 'Headers\t%s' % r.request.headers - print 'Data\t%s' % r.request.body - print "" - - print "Response:" - print 'Status\t%s' % r.status_code - print 'URL\t%s' % r.url - print 'Headers\t%s' % r.headers - print 'Logged in? ', "Yes" if "Logout" in r.text else "No" - print "" diff --git a/update_inara.py b/update_inara.py index 6b72b5b..748bccc 100755 --- a/update_inara.py +++ b/update_inara.py @@ -1,12 +1,12 @@ #!/usr/bin/python from edmc import companion -import inara +from inara.inara import InaraSession import utils settings = utils.get_settings() companion_session = companion.Session() -inara_session = inara.Session() +inara_session = InaraSession(settengs.get('inara', 'username'), settings.get('inara', 'password')) try: companion_session.login(settings.get('ed_companion', 'username'), settings.get('ed_companion', 'password')) @@ -14,11 +14,8 @@ except companion.VerificationRequired: code = raw_input("Input Verification Code: ") companion_session.verify(code) -inara_session.inara_login(settings.get('inara', 'username'), settings.get('inara', 'password')) -inara_session._inara_handled_request(inara_session.post, inara.URL_BASE) - data = companion_session.query() -inara_session.inara_update_credits(data['commander']['credits']) -inara_session.inara_update_location(data['lastSystem']['name']) +inara_session.update_credits(data['commander']['credits']) +inara_session.update_location(data['lastSystem']['name']) companion_session.close()