def query_es_for_top_tanks(config, era):
    now = datetime.utcnow()
    then = (now - timedelta(days=1))
    es = Elasticsearch(**config['elasticsearch'])
    if (era == 'ww2'):
        query = ww2_popular_tanks_query
    elif (era == 'cw'):
        query = cw_popular_tanks_query
    query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    response = es.search(index=config['tank index'], body=query)
    buckets = {'xbox': OrderedDict(), 'ps': OrderedDict()}
    for bucket in response['aggregations']['2']['buckets']:
        for subbucket in bucket['4']['buckets']:
            key = subbucket['key']
            for tank in subbucket['3']['buckets']:
                buckets[key][tank['key']] = int(tank['1']['value'])
    return buckets
def query_es_for_top_tanks(config, era):
    now = datetime.utcnow()
    then = (now - timedelta(days=1))
    es = Elasticsearch(**config['elasticsearch'])
    if (era == 'ww2'):
        query = ww2_popular_tanks_query
    elif (era == 'cw'):
        query = cw_popular_tanks_query
    query['query']['bool']['must'][(- 1)]['range']['date']['gte'] = then.strftime('%Y-%m-%d')
    query['query']['bool']['must'][(- 1)]['range']['date']['lte'] = now.strftime('%Y-%m-%d')
    response = es.search(index=config['tank index'], body=query)
    buckets = {'xbox': OrderedDict(), 'ps': OrderedDict()}
    for bucket in response['aggregations']['2']['buckets']:
        for subbucket in bucket['4']['buckets']:
            key = subbucket['key']
            for tank in subbucket['3']['buckets']:
                buckets[key][tank['key']] = int(tank['1']['value'])
    return buckets