Beispiel #1
0
def update_slot_session_recs():
    elastic_logger.info("Updating elasticsearch Slot Session Documents" )
    try:
        es = Elasticsearch([es_host])
        query = {
            'query': {
                'match_all': {},
            },
            'sort': {
                    'gaming_date.full_date': {"order": "desc"}
            },
            'size': '1'
        }
        res = es.search(index='slot_sessions', body=query)
        
        d = res['hits']['hits'][0]['_source']['gaming_date']['full_date']
        last_update = utc_to_local(parse(d))
        start_date = last_update + datetime.timedelta(days=1)
        today = datetime.datetime.now().date()
        end_date = today - datetime.timedelta(days=1)
        if start_date == end_date:
            slot_sessions_etl(start_date)
        else:
            dates = pd.date_range(start_date, end_date).tolist()
            for date in dates:
                slot_sessions_etl(date)
    except Exception, e:
            elastic_logger.exception(e)
Beispiel #2
0
def update_recs(model):
    elastic_logger.info("Updating elasticsearch %s Documents" % model.es_index)
    try:
        es = Elasticsearch([es_host])
        query = {
            'query': {
                'match_all': {},
            },
            'sort': {
                model.es_date_field: {
                    "order": "desc"
                }
            },
            'size': '1'
        }
        res = es.search(index=model.es_index, body=query)

        d = res['hits']['hits'][0]['_source'][model.es_date_field]
        last_update = utc_to_local(parse(d))
        start_date = last_update + datetime.timedelta(days=1)
        today = datetime.datetime.now().date()
        end_date = today - datetime.timedelta(days=1)
        if start_date == end_date:
            etl(start_date, model)
        else:
            dates = pd.date_range(start_date, end_date).tolist()
            for date in dates:
                etl(date, model)
    except Exception as e:
        elastic_logger.exception(e)
    elastic_logger.info("Update complete")