Modify eveapi to work with pyfa service, move all character API calls from EOS to Character service and use new network service
This commit is contained in:
@@ -18,12 +18,9 @@
|
||||
#===============================================================================
|
||||
|
||||
|
||||
import urllib2
|
||||
from sqlalchemy.orm import validates, reconstructor
|
||||
|
||||
from eos.effectHandlerHelpers import HandledItem
|
||||
from sqlalchemy.orm import validates, reconstructor
|
||||
import sqlalchemy.orm.exc as exc
|
||||
from eos import eveapi
|
||||
import eos
|
||||
|
||||
class Character(object):
|
||||
@@ -108,27 +105,6 @@ class Character(object):
|
||||
for skill in self.__skills:
|
||||
self.__skillIdMap[skill.itemID] = skill
|
||||
|
||||
def apiCharList(self, proxy=None):
|
||||
api = eveapi.EVEAPIConnection(proxy=proxy)
|
||||
auth = api.auth(keyID=self.apiID, vCode=self.apiKey)
|
||||
apiResult = auth.account.Characters()
|
||||
return map(lambda c: unicode(c.name), apiResult.characters)
|
||||
|
||||
def apiFetch(self, charName, proxy=None):
|
||||
api = eveapi.EVEAPIConnection(proxy=proxy)
|
||||
auth = api.auth(keyID=self.apiID, vCode=self.apiKey)
|
||||
apiResult = auth.account.Characters()
|
||||
charID = None
|
||||
for char in apiResult.characters:
|
||||
if char.name == charName:
|
||||
charID = char.characterID
|
||||
|
||||
if charID == None:
|
||||
return
|
||||
|
||||
sheet = auth.character(charID).CharacterSheet()
|
||||
self.apiUpdateCharSheet(sheet)
|
||||
|
||||
def apiUpdateCharSheet(self, sheet):
|
||||
del self.__skills[:]
|
||||
self.__skillIdMap.clear()
|
||||
|
||||
@@ -17,25 +17,23 @@
|
||||
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
|
||||
#===============================================================================
|
||||
|
||||
import eos.db
|
||||
import eos.types
|
||||
import copy
|
||||
import service
|
||||
import itertools
|
||||
from eos import eveapi
|
||||
import config
|
||||
import json
|
||||
import os.path
|
||||
import locale
|
||||
import threading
|
||||
import wx
|
||||
from codecs import open
|
||||
|
||||
from xml.etree import ElementTree
|
||||
from xml.dom import minidom
|
||||
|
||||
import gzip
|
||||
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import eos.types
|
||||
import service
|
||||
import config
|
||||
|
||||
|
||||
class CharacterImportThread(threading.Thread):
|
||||
def __init__(self, paths, callback):
|
||||
threading.Thread.__init__(self)
|
||||
@@ -240,19 +238,36 @@ class Character(object):
|
||||
|
||||
def charList(self, charID, userID, apiKey):
|
||||
char = eos.db.getCharacter(charID)
|
||||
try:
|
||||
char.apiID = userID
|
||||
char.apiKey = apiKey
|
||||
charList = char.apiCharList(proxy = service.settings.ProxySettings.getInstance().getProxySettings())
|
||||
char.chars = json.dumps(charList)
|
||||
return charList
|
||||
except:
|
||||
return None
|
||||
|
||||
char.apiID = userID
|
||||
char.apiKey = apiKey
|
||||
|
||||
api = service.EVEAPIConnection()
|
||||
auth = api.auth(keyID=userID, vCode=apiKey)
|
||||
apiResult = auth.account.Characters()
|
||||
charList = map(lambda c: unicode(c.name), apiResult.characters)
|
||||
|
||||
char.chars = json.dumps(charList)
|
||||
return charList
|
||||
|
||||
def apiFetch(self, charID, charName):
|
||||
char = eos.db.getCharacter(charID)
|
||||
char.defaultChar = charName
|
||||
char.apiFetch(charName, proxy = service.settings.ProxySettings.getInstance().getProxySettings())
|
||||
dbChar = eos.db.getCharacter(charID)
|
||||
dbChar.defaultChar = charName
|
||||
|
||||
api = service.EVEAPIConnection()
|
||||
auth = api.auth(keyID=dbChar.apiID, vCode=dbChar.apiKey)
|
||||
apiResult = auth.account.Characters()
|
||||
charID = None
|
||||
for char in apiResult.characters:
|
||||
if char.name == charName:
|
||||
charID = char.characterID
|
||||
|
||||
if charID == None:
|
||||
return
|
||||
|
||||
sheet = auth.character(charID).CharacterSheet()
|
||||
|
||||
dbChar.apiUpdateCharSheet(sheet)
|
||||
eos.db.commit()
|
||||
|
||||
def apiUpdateCharSheet(self, charID, sheet):
|
||||
|
||||
@@ -147,16 +147,27 @@
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
import httplib
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# This eveapi has been modified for pyfa.
|
||||
#
|
||||
# Specifically, the entire network request/response has been substituted for
|
||||
# pyfa's own implementation in service.network
|
||||
#
|
||||
# Additionally, various other parts have been changed to support urllib2
|
||||
# responses instead of httplib
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
import urlparse
|
||||
import urllib
|
||||
import copy
|
||||
import warnings
|
||||
|
||||
from xml.parsers import expat
|
||||
from time import strptime
|
||||
from calendar import timegm
|
||||
|
||||
import service
|
||||
|
||||
proxy = None
|
||||
proxySSL = False
|
||||
|
||||
@@ -384,35 +395,11 @@ class _RootContext(_Context):
|
||||
response = None
|
||||
|
||||
if response is None:
|
||||
if not _useragent:
|
||||
warnings.warn("No User-Agent set! Please use the set_user_agent() module-level function before accessing the EVE API.", stacklevel=3)
|
||||
network = service.Network.getInstance()
|
||||
|
||||
if self._proxy is None:
|
||||
req = path
|
||||
if self._scheme == "https":
|
||||
conn = httplib.HTTPSConnection(self._host)
|
||||
else:
|
||||
conn = httplib.HTTPConnection(self._host)
|
||||
else:
|
||||
req = self._scheme+'://'+self._host+path
|
||||
if self._proxySSL:
|
||||
conn = httplib.HTTPSConnection(*self._proxy)
|
||||
else:
|
||||
conn = httplib.HTTPConnection(*self._proxy)
|
||||
req = self._scheme+'://'+self._host+path
|
||||
|
||||
if kw:
|
||||
conn.request("POST", req, urllib.urlencode(kw), {"Content-type": "application/x-www-form-urlencoded", "User-Agent": _useragent or _default_useragent})
|
||||
else:
|
||||
conn.request("GET", req, "", {"User-Agent": _useragent or _default_useragent})
|
||||
|
||||
response = conn.getresponse()
|
||||
if response.status != 200:
|
||||
if response.status == httplib.NOT_FOUND:
|
||||
raise AttributeError("'%s' not available on API server (404 Not Found)" % path)
|
||||
elif response.status == httplib.FORBIDDEN:
|
||||
raise AuthenticationError(response.status, 'HTTP 403 - Forbidden')
|
||||
else:
|
||||
raise ServerError(response.status, "'%s' request failed (%s)" % (path, response.reason))
|
||||
response = network.request(req, network.EVE, kw)
|
||||
|
||||
if cache:
|
||||
store = True
|
||||
|
||||
Reference in New Issue
Block a user