Add evepraisal as price source

This commit is contained in:
DarkPhoenix
2019-06-03 18:02:48 +03:00
parent 933c84466f
commit d451bda7ed
7 changed files with 151 additions and 47 deletions

View File

@@ -1 +1 @@
__all__ = ['evemarketer', 'evemarketdata']
__all__ = ['evemarketer', 'evemarketdata', 'evepraisal']

View File

@@ -31,7 +31,7 @@ pyfalog = Logger(__name__)
class EveMarketData:
name = "eve-marketdata.com"
name = 'eve-marketdata.com'
def __init__(self, priceMap, system, fetchTimeout):
# Try selected system first
@@ -42,24 +42,24 @@ class EveMarketData:
@staticmethod
def fetchPrices(priceMap, fetchTimeout, system=None):
params = {"type_ids": ','.join(str(typeID) for typeID in priceMap)}
params = {'type_ids': ','.join(str(typeID) for typeID in priceMap)}
if system is not None:
params["system_id"] = system
baseurl = "https://eve-marketdata.com/api/item_prices.xml"
params['system_id'] = system
baseurl = 'https://eve-marketdata.com/api/item_prices.xml'
network = Network.getInstance()
data = network.request(baseurl, network.PRICES, params=params, timeout=fetchTimeout)
data = network.get(url=baseurl, type=network.PRICES, params=params, timeout=fetchTimeout)
xml = minidom.parseString(data.text)
types = xml.getElementsByTagName("eve").item(0).getElementsByTagName("price")
types = xml.getElementsByTagName('eve').item(0).getElementsByTagName('price')
# Cycle through all types we've got from request
for type_ in types:
# Get data out of each typeID details tree
typeID = int(type_.getAttribute("id"))
typeID = int(type_.getAttribute('id'))
try:
price = float(type_.firstChild.data)
except (TypeError, ValueError):
pyfalog.warning("Failed to get price for: {0}", type_)
pyfalog.warning('Failed to get price for: {0}', type_)
continue
# eve-marketdata returns 0 if price data doesn't even exist for the item

View File

@@ -31,7 +31,7 @@ pyfalog = Logger(__name__)
class EveMarketer:
name = "evemarketer"
name = 'evemarketer'
def __init__(self, priceMap, system, fetchTimeout):
# Try selected system first
@@ -42,24 +42,24 @@ class EveMarketer:
@staticmethod
def fetchPrices(priceMap, fetchTimeout, system=None):
params = {"typeid": {typeID for typeID in priceMap}}
params = {'typeid': {typeID for typeID in priceMap}}
if system is not None:
params["usesystem"] = system
baseurl = "https://api.evemarketer.com/ec/marketstat"
params['usesystem'] = system
baseurl = 'https://api.evemarketer.com/ec/marketstat'
network = Network.getInstance()
data = network.request(baseurl, network.PRICES, params=params, timeout=fetchTimeout)
data = network.get(url=baseurl, type=network.PRICES, params=params, timeout=fetchTimeout)
xml = minidom.parseString(data.text)
types = xml.getElementsByTagName("marketstat").item(0).getElementsByTagName("type")
types = xml.getElementsByTagName('marketstat').item(0).getElementsByTagName('type')
# Cycle through all types we've got from request
for type_ in types:
# Get data out of each typeID details tree
typeID = int(type_.getAttribute("id"))
sell = type_.getElementsByTagName("sell").item(0)
# If price data wasn't there, set price to zero
typeID = int(type_.getAttribute('id'))
sell = type_.getElementsByTagName('sell').item(0)
# If price data wasn't there, skip the item
try:
percprice = float(sell.getElementsByTagName("percentile").item(0).firstChild.data)
percprice = float(sell.getElementsByTagName('percentile').item(0).firstChild.data)
except (TypeError, ValueError):
pyfalog.warning("Failed to get price for: {0}", type_)
pyfalog.warning('Failed to get price for: {0}', type_)
continue
# Price is 0 if evemarketer has info on this item, but it is not available

View File

@@ -0,0 +1,76 @@
# =============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of pyfa.
#
# pyfa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyfa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
# =============================================================================
from logbook import Logger
from eos.saveddata.price import PriceStatus
from service.network import Network
from service.price import Price
pyfalog = Logger(__name__)
systemAliases = {
None: 'universe',
30000142: 'jita',
30002187: 'amarr',
30002659: 'dodixie',
30002510: 'rens',
30002053: 'hek'}
class EvePraisal:
name = 'evepraisal'
def __init__(self, priceMap, system, fetchTimeout):
# Try selected system first
self.fetchPrices(priceMap, max(2 * fetchTimeout / 3, 2), system)
# If price was not available - try globally
if priceMap:
self.fetchPrices(priceMap, max(fetchTimeout / 3, 2))
@staticmethod
def fetchPrices(priceMap, fetchTimeout, system=None):
jsonData = {
'market_name': systemAliases[system],
'items': [{'type_id': typeID for typeID in priceMap}]}
baseurl = 'https://evepraisal.com/appraisal/structured.json'
network = Network.getInstance()
resp = network.post(baseurl, network.PRICES, jsonData=jsonData, timeout=fetchTimeout)
data = resp.json()
try:
itemsData = data['appraisal']['items']
except (KeyError, TypeError):
return False
# Cycle through all types we've got from request
for itemData in itemsData:
try:
typeID = int(itemData['typeID'])
percprice = itemData['prices']['sell']['percentile']
except (KeyError, TypeError):
continue
# evepraisal returns 0 if price data doesn't even exist for the item
if percprice == 0:
continue
priceMap[typeID].update(PriceStatus.fetchSuccess, percprice)
del priceMap[typeID]
Price.register(EvePraisal)