Use new inara.py library instead of having 2 versions of the code.
This commit is contained in:
parent
a7067cd2ee
commit
f009aa0ca0
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -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
|
||||
|
|
1
inara
Submodule
1
inara
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 010ff377e5b4af772f2dbe2736608cee4f04f58a
|
72
inara.py
72
inara.py
|
@ -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 ""
|
|
@ -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()
|
||||
|
|
Reference in New Issue
Block a user