Пример #1
0
def task_update_adjusted_price(self):
    """ Task that update the adjusted prices from the API """
    self.start()
    item_adjusted_price = []
    count = 0

    market_price = esiclient.request(get_markets_prices())

    if market_price.status == 200:
        for item_price in market_price.data:
            count += 1
            item_adjusted_price.append({
                'item_id':
                item_price.type_id,
                'price':
                item_price.adjusted_price or 0.00
            })

        db.engine.execute("TRUNCATE TABLE %s" %
                          ItemAdjustedPrice.__tablename__)
        db.engine.execute(ItemAdjustedPrice.__table__.insert(),
                          item_adjusted_price)
        db.session.commit()
        self.end(TaskState.SUCCESS)

    else:
        self.end(TaskState.ERROR)
Пример #2
0
def update_adjusted_price():
    """ Get market prices from ESI and update the database.
    Raises exception if database cannot be updated.

    Returns
    -------
    Dict
        the prices that were updated.

    """
    item_adjusted_price = {}
    count = 0
    market_price = esiclient.request(get_markets_prices())

    if market_price.status == 200:
        for item_price in market_price.data:
            count += 1
            item_adjusted_price[item_price.type_id] = {
                'item_id': item_price.type_id,
                'price': item_price.adjusted_price or 0.00
            }

        db.engine.execute("TRUNCATE TABLE %s" %
                          ItemAdjustedPrice.__tablename__)
        db.engine.execute(ItemAdjustedPrice.__table__.insert(),
                          list(item_adjusted_price.values()))
        db.session.commit()
        return item_adjusted_price
    return None