|
@@ -17,6 +17,8 @@ import threading
|
|
from googleapiclient.discovery import build
|
|
from googleapiclient.discovery import build
|
|
from oauth2client.service_account import ServiceAccountCredentials
|
|
from oauth2client.service_account import ServiceAccountCredentials
|
|
import dataset
|
|
import dataset
|
|
|
|
+import pymysql
|
|
|
|
+pymysql.install_as_MySQLdb()
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
@@ -28,13 +30,14 @@ table=db['ga_pagepath']
|
|
|
|
|
|
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
|
|
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
|
|
#KEY_FILE_LOCATION = '/root/src/kw_tools/monitor/choozmo-ga-beee24b7a4c1.json' #'c:\\keys\\choozmo-ga-beee24b7a4c1.json'
|
|
#KEY_FILE_LOCATION = '/root/src/kw_tools/monitor/choozmo-ga-beee24b7a4c1.json' #'c:\\keys\\choozmo-ga-beee24b7a4c1.json'
|
|
-KEY_FILE_LOCATION = 'c:\\keys\\corded-velocity-301807-9262189e4dd5.json'
|
|
|
|
|
|
+# KEY_FILE_LOCATION = 'c:\\keys\\corded-velocity-301807-9262189e4dd5.json'
|
|
|
|
+KEY_FILE_LOCATION = '/Users/zooeytsai/Downloads/corded-velocity-301807-9262189e4dd5.json'
|
|
|
|
|
|
VIEW_ID = '213054263'
|
|
VIEW_ID = '213054263'
|
|
|
|
|
|
# line notify header
|
|
# line notify header
|
|
headers = {
|
|
headers = {
|
|
- "Authorization": "Bearer " + "WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD",
|
|
|
|
|
|
+ "Authorization": "Bearer " + "zsaS4I79fkbun9LLF8mQmeHL4PlEtBtN7OLzTp8m72Y",
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
}
|
|
}
|
|
|
|
|
|
@@ -45,7 +48,7 @@ def creat_table():
|
|
com_table.append([24,70000])
|
|
com_table.append([24,70000])
|
|
print(com_table)
|
|
print(com_table)
|
|
|
|
|
|
-def send_msg(kw):
|
|
|
|
|
|
+def send_msg_pg(kw):
|
|
# line notify send message
|
|
# line notify send message
|
|
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') #現在時間
|
|
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') #現在時間
|
|
hour = datetime.now().strftime('%H')
|
|
hour = datetime.now().strftime('%H')
|
|
@@ -54,15 +57,16 @@ def send_msg(kw):
|
|
for i in range(0,25):
|
|
for i in range(0,25):
|
|
if int(hour)+1==com_table[i][0]:
|
|
if int(hour)+1==com_table[i][0]:
|
|
print(i)
|
|
print(i)
|
|
- if int(kw) > com_table[i][1] :
|
|
|
|
|
|
+ if int(kw) > com_table[i][1] :
|
|
complet="是"
|
|
complet="是"
|
|
elif int(hour) == 24:
|
|
elif int(hour) == 24:
|
|
- if int(kw) > 70000 :
|
|
|
|
|
|
+ if int(kw) > 70000 :
|
|
complet="是"
|
|
complet="是"
|
|
params = {"message": "\n現在時間: " + current_time + "\n當前pageViews: "+kw + "\n是否達標: " + complet}
|
|
params = {"message": "\n現在時間: " + current_time + "\n當前pageViews: "+kw + "\n是否達標: " + complet}
|
|
print(params)
|
|
print(params)
|
|
-# r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
|
|
|
|
-# print(r.text)
|
|
|
|
|
|
+ return params
|
|
|
|
+ # r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
|
|
|
|
+ # print(r.text)
|
|
|
|
|
|
|
|
|
|
def initialize_analyticsreporting():
|
|
def initialize_analyticsreporting():
|
|
@@ -126,6 +130,7 @@ def print_response(response):
|
|
# print(ga_dict)
|
|
# print(ga_dict)
|
|
|
|
|
|
def main():
|
|
def main():
|
|
|
|
+ creat_table()
|
|
analytics = initialize_analyticsreporting()
|
|
analytics = initialize_analyticsreporting()
|
|
#(FB_|facebook|IG_|LINE_|LINEMP_|qsear.ch)
|
|
#(FB_|facebook|IG_|LINE_|LINEMP_|qsear.ch)
|
|
current_time = datetime.now().strftime('%Y-%m-%d') #現在時間
|
|
current_time = datetime.now().strftime('%Y-%m-%d') #現在時間
|
|
@@ -146,10 +151,10 @@ def main():
|
|
print(elmt)
|
|
print(elmt)
|
|
hour = datetime.now().strftime('%H')
|
|
hour = datetime.now().strftime('%H')
|
|
if int(hour)+1 > 8 :
|
|
if int(hour)+1 > 8 :
|
|
- send_msg(elmt['ga:pageviews'])
|
|
|
|
|
|
+ message = send_msg_pg(elmt['ga:pageviews'])
|
|
# result.append(elmt)
|
|
# result.append(elmt)
|
|
print('inserting.....')
|
|
print('inserting.....')
|
|
-
|
|
|
|
|
|
+ return message
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
creat_table()
|
|
creat_table()
|
|
main()
|
|
main()
|