예제 #1
0
파일: cart.py 프로젝트: miladmyled/GA_ETL
def fetch_data(_id, analytics, input_date, mode):
    response = get_report(_id, analytics, mode, input_date, input_date, '0')
    df = ga_engine.create_df(response)
    dataframes = []
    dataframes.append(df)
    idx = 0
    while (len(df.index) == BATCH_SIZE):
        idx += BATCH_SIZE
        response = get_report(_id, analytics, mode, input_date, input_date, str(idx))
        df = ga_engine.create_df(response)
        dataframes.append(df)

    return pd.concat(dataframes)
예제 #2
0
def fetch_data_custom(_id, analytics, input_date, end_date, noyears, platform):
    if noyears == 1:
        if platform == 'app':
            response = get_report_app(_id, analytics, 'year', input_date,
                                      end_date, '0')
        else:
            response = get_report_web(_id, analytics, 'year', input_date,
                                      end_date, '0')
    else:
        if platform == 'app':
            response = get_report_app(_id, analytics, '2years', input_date,
                                      end_date, '0')
        else:
            response = get_report_web(_id, analytics, '2years', input_date,
                                      end_date, '0')
    df = ga_engine.create_df(response)
    dataframes = []
    dataframes.append(df)
    idx = 0
    while (len(df.index) == BATCH_SIZE):
        idx += BATCH_SIZE
        if noyears == 1:
            if platform == 'app':
                response = get_report_app(_id, analytics, 'year', input_date,
                                          end_date, str(idx))
            else:
                response = get_report_web(_id, analytics, 'year', input_date,
                                          end_date, str(idx))
        else:
            if platform == 'app':
                response = get_report_app(_id, analytics, '2years', input_date,
                                          end_date, str(idx))
            else:
                response = get_report_web(_id, analytics, '2years', input_date,
                                          end_date, str(idx))
        df = ga_engine.create_df(response)
        dataframes.append(df)

    return pd.concat(dataframes)
예제 #3
0
def get_report(_id, analytics , start='2017-03-01', end='2017-03-01', page='0'):

        df = ga_engine.create_df(analytics.reports().batchGet(
            body = {
                'reportRequests': [
                    {
                        'viewId': _id,
                        'dateRanges': [{'startDate': start, 'endDate': end}],
                        'metrics': [{'expression': 'ga:users'}],
                        'samplingLevel': 'LARGE',
                        'pageToken': page,
                        'pageSize': BATCH_SIZE
                    }]
            }
        ).execute())
        return df