Commit e79a6ceb0390c473a0ab627a442ef7d815a72907

Authored by Noah ago
1 parent 43a5084e4d
Exists in master

mau 추가

Showing 2 changed files with 34 additions and 7 deletions Side-by-side Diff

analyticsreporting.dat View file @ e79a6ce
1   -{"_module": "oauth2client.client", "scopes": ["https://www.googleapis.com/auth/analytics.readonly"], "token_expiry": "2016-06-30T09:06:40Z", "id_token": null, "access_token": "ya29.Ci8RA5d1vZMq-ZtmEnvWRjxp5CpIOsyjfv7y_p90fNj8OjVbKq-F8Lf5n_iqBbHAXQ", "token_uri": "https://accounts.google.com/o/oauth2/token", "invalid": false, "token_response": {"access_token": "ya29.Ci8RA5d1vZMq-ZtmEnvWRjxp5CpIOsyjfv7y_p90fNj8OjVbKq-F8Lf5n_iqBbHAXQ", "token_type": "Bearer", "expires_in": 3600}, "client_id": "884418547933-e08agllr5v2kp2r3i68ld31ptl3bj4rt.apps.googleusercontent.com", "token_info_uri": "https://www.googleapis.com/oauth2/v3/tokeninfo", "client_secret": "yHgeC50DdYVLTjdHwG00eRjA", "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials", "refresh_token": "1/XLGetj18dRnqooCzqSFfNELsMJ2yp6umjkPm8RUxnxM", "user_agent": null}
  1 +{"_module": "oauth2client.client", "scopes": ["https://www.googleapis.com/auth/analytics.readonly"], "token_expiry": "2016-07-11T02:11:58Z", "id_token": null, "access_token": "ya29.CjAdA5ilL1pj0wmrvCWARXhX_ZkvMMJ1fYrBxkkXts8fsBq72LFgotan1D7IWsmSn-4", "token_uri": "https://accounts.google.com/o/oauth2/token", "invalid": false, "token_response": {"access_token": "ya29.CjAdA5ilL1pj0wmrvCWARXhX_ZkvMMJ1fYrBxkkXts8fsBq72LFgotan1D7IWsmSn-4", "token_type": "Bearer", "expires_in": 3600}, "client_id": "884418547933-e08agllr5v2kp2r3i68ld31ptl3bj4rt.apps.googleusercontent.com", "token_info_uri": "https://www.googleapis.com/oauth2/v3/tokeninfo", "client_secret": "yHgeC50DdYVLTjdHwG00eRjA", "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "_class": "OAuth2Credentials", "refresh_token": "1/XLGetj18dRnqooCzqSFfNELsMJ2yp6umjkPm8RUxnxM", "user_agent": null}
... ... @@ -43,7 +43,7 @@
43 43  
44 44 return analytics
45 45  
46   -def get_report(analytics):
  46 +def get_dau(analytics):
47 47 # Use the Analytics Service Object to query the Analytics Reporting API V4.
48 48 return analytics.reports().batchGet(
49 49 body={
50 50  
51 51  
... ... @@ -59,9 +59,24 @@
59 59 ).execute()
60 60  
61 61  
62   -def print_response(response):
  62 +def get_mau(analytics):
  63 + # Use the Analytics Service Object to query the Analytics Reporting API V4.
63 64  
  65 + week_first_day = str(datetime.date.today()+datetime.timedelta(days=-datetime.date.today().day + 1))
  66 + return analytics.reports().batchGet(
  67 + body={
  68 + 'reportRequests': [
  69 + {
  70 + 'viewId': VIEW_ID,
  71 + 'dateRanges': [{'startDate': week_first_day, 'endDate': 'today'}],
  72 + 'metrics': [{'expression': 'ga:Users'}]
  73 + }]
  74 + }
  75 + ).execute()
64 76  
  77 +
  78 +def print_response(response):
  79 +
65 80 for report in response.get('reports', []):
66 81 columnHeader = report.get('columnHeader', {})
67 82 dimensionHeaders = columnHeader.get('dimensions', [])
68 83  
69 84  
70 85  
... ... @@ -101,14 +116,26 @@
101 116  
102 117  
103 118 def main():
  119 +
  120 +
104 121 analytics = initialize_analyticsreporting()
105   - response = get_report(analytics)
106   - val = return_response(response)
107 122  
108   - dau = int(val.split(":")[2])
  123 + dau = get_dau(analytics)
  124 + val = return_response(dau)
  125 +
  126 + dau_val = int(val.split(":")[2])
109 127 yesterday = str(datetime.date.today()+datetime.timedelta(days=-1))
110 128 datadb = DataDB()
111   - sql = "insert into web_dau (`cdate`, `dau`) values ('%s', %d);"%(yesterday,dau)
  129 + sql = "REPLACE into web_dau (`cdate`, `dau`) values ('%s', %d);"%(yesterday,dau_val)
  130 + datadb.ga_insert(sql)
  131 +
  132 + mau = get_mau(analytics)
  133 + val = return_response(mau)
  134 +
  135 + mau_val = int(val.split(":")[2])
  136 + week_first_day = str(datetime.date.today()+datetime.timedelta(days=-datetime.date.today().day + 1))
  137 + datadb = DataDB()
  138 + sql = "REPLACE into web_mau (`cdate`, `mau`) values ('%s', %d);"%(week_first_day,mau_val)
112 139 datadb.ga_insert(sql)
113 140  
114 141 if __name__ == '__main__':