zooeytsai 2 anni fa
parent
commit
2a1c77a14e
2 ha cambiato i file con 19 aggiunte e 11 eliminazioni
  1. 5 2
      INNNews/notifytest.py
  2. 14 9
      monitor/GA_innnews.py

+ 5 - 2
INNNews/notifytest.py

@@ -20,6 +20,7 @@ import sys
 import docker
 import pymysql
 pymysql.install_as_MySQLdb()
+from monitor import GA_innnews
 
 headers = {
         "Authorization": "Bearer " + "zsaS4I79fkbun9LLF8mQmeHL4PlEtBtN7OLzTp8m72Y",
@@ -29,7 +30,9 @@ headers = {
 
 
 def send_msg(kw):
-    params = {"message": kw}  
+    send_message = GA_innnews.main()
+    params = {"message": kw+send_message['message']}
+    print('通知結果',params)
     r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
 
 while True:
@@ -47,4 +50,4 @@ while True:
     send_msg(msg+result)
     time.sleep(1800)
 
-# schtasks /create /sc minute /mo 10 /st 09:00 /et 23:00 /tn "linebat" /tr "C:\tmp\inn_line.bat"
+# schtasks /create /sc minute /mo 30 /sd 2022/05/050 /st 9:00 /et 23:00 /tn "linebat" /tr "C:\tmp\inn_line.bat"

+ 14 - 9
monitor/GA_innnews.py

@@ -17,6 +17,8 @@ import threading
 from googleapiclient.discovery import build
 from oauth2client.service_account import ServiceAccountCredentials
 import dataset
+import pymysql
+pymysql.install_as_MySQLdb()
 from datetime import datetime
 
 
@@ -28,13 +30,14 @@ table=db['ga_pagepath']
 
 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 = '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'
 
 # line notify header
 headers = {
-        "Authorization": "Bearer " + "WekCRfnAirSiSxALiD6gcm0B56EejsoK89zFbIaiZQD",
+        "Authorization": "Bearer " + "zsaS4I79fkbun9LLF8mQmeHL4PlEtBtN7OLzTp8m72Y",
         "Content-Type": "application/x-www-form-urlencoded"
 }
 
@@ -45,7 +48,7 @@ def creat_table():
   com_table.append([24,70000])
   print(com_table)
 
-def send_msg(kw):
+def send_msg_pg(kw):
   # line notify send message
     current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') #現在時間
     hour = datetime.now().strftime('%H') 
@@ -54,15 +57,16 @@ def send_msg(kw):
     for i in range(0,25):
       if int(hour)+1==com_table[i][0]:
         print(i)
-        if int(kw) > com_table[i][1] : 
+        if int(kw) > com_table[i][1] :
           complet="是"
       elif int(hour) == 24:
-        if int(kw) > 70000 : 
+        if int(kw) > 70000 :
           complet="是"
     params = {"message": "\n現在時間: " + current_time + "\n當前pageViews: "+kw + "\n是否達標: " + complet}  
     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():
@@ -126,6 +130,7 @@ def print_response(response):
 #        print(ga_dict)
 
 def main():
+  creat_table()
   analytics = initialize_analyticsreporting()
 #(FB_|facebook|IG_|LINE_|LINEMP_|qsear.ch)
   current_time = datetime.now().strftime('%Y-%m-%d') #現在時間
@@ -146,10 +151,10 @@ def main():
     print(elmt)
     hour = datetime.now().strftime('%H')
     if int(hour)+1 > 8 :
-      send_msg(elmt['ga:pageviews'])
+      message = send_msg_pg(elmt['ga:pageviews'])
 #      result.append(elmt)
   print('inserting.....')
-
+  return message
 if __name__ == '__main__':
   creat_table()
   main()