Prechádzať zdrojové kódy

依平台不同執行

zooeytsai 2 rokov pred
rodič
commit
668012fdde
1 zmenil súbory, kde vykonal 23 pridanie a 17 odobranie
  1. 23 17
      monitor/GA_innnews.py

+ 23 - 17
monitor/GA_innnews.py

@@ -20,18 +20,21 @@ import dataset
 import pymysql
 pymysql.install_as_MySQLdb()
 from datetime import datetime
-
+import platform
 
 db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
 db.query('delete from ga_pagepath')
 db.begin()
 
 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 = '/Users/zooeytsai/Downloads/corded-velocity-301807-9262189e4dd5.json'
+platform_now = platform.system().lower()
+if platform_now == 'linux':
+  KEY_FILE_LOCATION = '/root/src/kw_tools/monitor/choozmo-ga-beee24b7a4c1.json' #'c:\\keys\\choozmo-ga-beee24b7a4c1.json'
+elif platform_now == 'windows':
+  KEY_FILE_LOCATION = 'c:\gitlab\kw_tools\monitor\corded-velocity-301807-9262189e4dd5.json'
+else:
+  KEY_FILE_LOCATION = '/Users/zooeytsai/Downloads/corded-velocity-301807-9262189e4dd5.json'
 
 VIEW_ID = '213054263'
 
@@ -44,25 +47,28 @@ headers = {
 com_table = []
 def creat_table():
   for i in range(0,24):
-    com_table.append([i,2920*i])
-  com_table.append([24,70000])
+    com_table.append([i,6000])
+  # com_table.append([24,70000])
   print(com_table)
 
-def send_msg_pg(kw):
+def send_msg_pg(pv):
   # line notify send message
     current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') #現在時間
     hour = datetime.now().strftime('%H') 
     # 判斷是否達標
     complet="否"
-    for i in range(0,25):
-      if int(hour)+1==com_table[i][0]:
-        print(i)
-        if int(kw) > com_table[i][1] :
-          complet="是"
-      elif int(hour) == 24:
-        if int(kw) > 70000 :
-          complet="是"
-    params = {"message": "\n現在時間: " + current_time + "\n當前pageViews: "+kw + "\n是否達標: " + complet}  
+    # for i in range(0,25):
+    #   if int(hour)+1==com_table[i][0]:
+    #     print(i)
+    #     if int(kw) > com_table[i][1] :
+    #       complet="是"
+    #   elif int(hour) == 24:
+    #     if int(kw) > 70000 :
+    #       complet="是"
+    print('網頁瀏覽量',pv)
+    if int(pv) > 6000:
+      complet = "是"
+    params = {"message": "\n現在時間: " + current_time + "\n當前pageViews: "+pv + "\n是否達標: " + complet}
     print(params)
     return params
     # r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)