Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update_market_history_data(region_id, type_id):
- """Gets a types market data and store it in the datastore."""
- market = crest_market.Market(crest_api.API())
- market_data = market.get_price_history(region_id, type_id)
- market_data['items'] = reversed(market_data['items'])
- for day in market_data['items']:
- entry_date = datetime.strptime(day['date'], '%Y-%m-%dT%H:%M:%S').date()
- entry_date_str = '%s' % entry_date
- parent_key = ndb.Key(m_misc.TypeModel, type_id)
- market_history_entry = m_market.MarketHistoryEntryModel.get_by_id(entry_date_str, parent_key)
- if market_history_entry is None:
- logging.info('Market history data for %s on %s does not exist. Adding.' % (type_id, entry_date_str))
- market_history_entry = m_market.MarketHistoryEntryModel(id=entry_date_str, parent=parent_key)
- market_history_entry.date = entry_date
- market_history_entry.volume = day['volume']
- market_history_entry.order_count = day['orderCount']
- market_history_entry.price_average = day['avgPrice']
- market_history_entry.price_high = day['highPrice']
- market_history_entry.price_low = day['lowPrice']
- market_history_entry.put()
Advertisement
Add Comment
Please, Sign In to add comment