def getShopTrades(access_token, fromTsmp, toTsmp): """根据授权码和时间戳获取交易数据 """ now = datetime.now() interval = 10 info = [] fromTsmp = datetime.strptime(fromTsmp, '%Y-%m-%d %H:%M:%S') toTsmp = datetime.strptime(toTsmp, '%Y-%m-%d %H:%M:%S') cursorTsmp = toTsmp while 1: if cursorTsmp < fromTsmp: break curFromTsmp = cursorTsmp - timedelta(interval) curFromTsmp = (fromTsmp if curFromTsmp < fromTsmp else curFromTsmp) curToTsmp = cursorTsmp if curToTsmp <= curFromTsmp: break metadata = getTrades(access_token, curFromTsmp.strftime('%Y-%m-%d %H:%M:%S'), curToTsmp.strftime('%Y-%m-%d %H:%M:%S')) if metadata['trades_sold_get_response']['total_results'] > 0: info.extend(metadata) cursorTsmp -= timedelta(interval) return info
def updateShopTrades(access_token): now = datetime.now() interval = 10 for i in range(1, 91): if i % interval == 0: starts = now - timedelta(i) ends = now - timedelta(i - interval) metadata = getTrades(access_token, starts.strftime('%Y-%m-%d %H:%M:%S'), ends.strftime('%Y-%m-%d %H:%M:%S')) metadata = json.loads(metadata, encoding='GBK') if metadata['trades_sold_get_response']['total_results'] > 0: saveTrades(metadata['trades_sold_get_response']['trades' ]['trade']) pass
def updateShopTrades(access_token): now = datetime.now() interval = 10 for i in range(1, 91): if i % interval == 0: starts = now - timedelta(i) ends = now - timedelta(i - interval) metadata = getTrades(access_token, starts.strftime('%Y-%m-%d %H:%M:%S'), ends.strftime('%Y-%m-%d %H:%M:%S')) metadata = json.loads(metadata, encoding='GBK') if metadata['trades_sold_get_response']['total_results'] > 0: saveTrades( metadata['trades_sold_get_response']['trades']['trade']) pass