1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Add setcredits method

This commit is contained in:
AnthorNet 2016-10-26 14:08:37 +02:00 committed by GitHub
parent 31af8be048
commit 43ba88fe8c

25
edsm.py
View File

@ -167,3 +167,28 @@ class EDSM:
if msgnum // 100 not in (1,4):
raise Exception(_('Error: EDSM {MSG}').format(MSG=msg))
def setcredits(self, credits):
if not credits:
return
try:
url = 'https://www.edsm.net/api-commander-v1/set-credits?commanderName=%s&apiKey=%s&fromSoftware=%s&fromSoftwareVersion=%s' % (
urllib2.quote(config.get('edsm_cmdrname').encode('utf-8')),
urllib2.quote(config.get('edsm_apikey')),
urllib2.quote(applongname),
urllib2.quote(appversion)
)
url += '&%s=%s' % ('balance', urllib2.quote('%d;%d' % credits['balance']))
url += '&%s=%s' % ('loan', urllib2.quote('%d;%d' % credits['loan']))
r = self.opener.open(url, timeout=EDSM._TIMEOUT)
reply = json.loads(r.read())
(msgnum, msg) = reply['msgnum'], reply['msg']
except:
if __debug__: print_exc()
raise Exception(_("Error: Can't connect to EDSM"))
if msgnum // 100 not in (1,4):
raise Exception(_('Error: EDSM {MSG}').format(MSG=msg))