def evemarketer(self, type_ids=[]): db_types = self.outdated(type_ids, 'evemarketer') if len(db_types) > 0: ids = ','.join([str(x.id) for x in db_types]) all_prices = requests.get( url='https://api.evemarketer.com/ec/marketstat/json?typeid=' + ids + '®ionlimit=10000002') all_prices_hash = {} for r in all_prices.json(): type_id = r['sell']['forQuery']['types'][0] all_prices_hash[type_id] = r ts = datetime.now().isoformat() for db_type in db_types: db_price = Price.query.filter( Price.source == 'evemarketer', Price.type_id == db_type.id).order_by( Price.id.desc()).first() if not db_price: db_price = Price(source='evemarketer', type_id=db_type.id) db_price.buy = all_prices_hash[ db_type.id]['buy']['fivePercent'] db_price.sell = all_prices_hash[ db_type.id]['sell']['fivePercent'] db_price.updated_at = ts db.session.begin_nested() try: db.session.add(db_price) db.session.commit() except IntegrityError: db.session.rollback() db.session.commit()
def esi(self, type_ids=[]): db_types = self.outdated(type_ids, 'esi') if len(db_types) > 0: all_prices = esiclient.markets.prices() all_prices_hash = {} for r in all_prices: all_prices_hash[r['type_id']] = r['adjusted_price'] ts = datetime.now().isoformat() for db_type in db_types: db_price = Price.query.filter( Price.source == 'esi', Price.type_id == db_type.id).first() if not db_price: db_price = Price(source='esi', type_id=db_type.id) db_price.buy = all_prices_hash[db_price.type_id] db_price.sell = all_prices_hash[db_price.type_id] db_price.updated_at = ts db.session.add(db_price) db.session.commit()