zooey 2 年 前
コミット
f2ea401563

+ 1 - 1
INNNews/general_clickbot_local.py

@@ -72,7 +72,7 @@ def run_once(q):
     global driver
     result = []
     user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
-    s = Service('C:\/Users\/s1301\/Downloads\/chromedriver_108\/chromedriver')
+    s = Service('C:\/Users\/s1301\/Downloads\/chromedriver_110\/chromedriver')
     options = webdriver.ChromeOptions()
     options.add_argument('--headless')
     # options.add_argument('--remote-debugging-port=9222')

+ 4 - 4
SEO/clickbot_100.py

@@ -45,11 +45,11 @@ def process_one():
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
     lst=[]
     table=db['google_rank']
-    cursor = db.query('select term,domain from seo.selected_kw where client="CLIQ露營椅"')
+    # cursor = db.query('select term,domain from seo.selected_kw where client="CLIQ露營椅"')
     # cursor = db.query('select term,url from seo.sns_kw where client="英雄難國美人酒"')
     # cursor = db.query('select term from seo.selected_kw where client="plantA"')
     # cursor = db.query('select term,domain from seo.select_kw where id between 2216 and 2255')
-    # cursor = db.query('select term,domain from seo.select_kw where client="only實驗教育"')
+    cursor = db.query('select term,domain from seo.select_kw where client="美麗馨"')
     # cursor=db.query('select term from selected_kw and term not in (SELECT distinct(keyword) FROM ig_tags.save_result where url like "%beastparadise.net%" and datediff(now(),dt)=0)')
     for c in cursor:
         lst.append([c['term'],c['domain']])
@@ -63,7 +63,7 @@ def process_one():
         driver.get(googleurl)
         time.sleep(60)
         print(driver.current_url)
-        driver.save_screenshot('C:\/Users\/s1301\/Pictures\/Saved Pictures\/'+i[0]+'.png')
+        # driver.save_screenshot('C:\/Users\/s1301\/Pictures\/Saved Pictures\/'+i[0]+'.png')
         df=pd.DataFrame()
         elmts=driver.find_elements(By.XPATH,"//div[@class='yuRUbf']/a")
         print('結果數量',len(elmts))
@@ -93,7 +93,7 @@ def process_one():
         df['結果網址']=datadict['結果網址']
         df['結果名次']=datadict['結果名次']
 
-        # df.to_excel('C:\/Users\/s1301\/Pictures\/Saved Pictures\soapdays\/'+i[0]+".xls")
+        df.to_excel('C:\/Users\/s1301\/Pictures\/Saved Pictures\soapdays\/'+i[0]+".xls")
 
         driver.quit()
         print('等待')

+ 3 - 3
SEO/clickbot_100_one.py

@@ -43,11 +43,11 @@ def restart_browser():
 def process_one():
     # lst=['信義房屋','信義 房屋','信義房仲','信義 房仲']
     # lst=['雙響泡','双響泡','雙響砲']
-    lst = ['双響泡']
+    # lst = ['清原']
     # lst = ['龔國權']
     # lst = ['巨力搬家']
-    # lst = ['飲料店加盟金比較','2023飲料店加盟','茶聚加盟']
-    date='0216'
+    lst = ['樂活眼鏡評價','lohas眼鏡評價','lohas評價']
+    date='0220'
     for term in lst:
         driver=restart_browser()
         escaped_search_term=urllib.parse.quote(term)

+ 18 - 18
SEO/csv_to_sql.py

@@ -7,38 +7,38 @@ pymysql.install_as_MySQLdb()
 
 
 db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
-table=db['seo_jobs']
+# table=db['seo_jobs']
 # table=db['selected_kw']
 # table=db['sns_kw']
-# table=db['select_kw']
-client='清原'
-# domain='ionly.com.tw'
+table=db['select_kw']
+client='美麗馨'
+domain='lisinbeauty.com'
 # for index,row in df.iterrows():
 # with open("C:\/Users\/s1301\/Documents\/新飛國際遊學SEO - 關鍵字12.08.csv") as f:
 #     data_all = f.readlines()
 # print(data_all)
 f = open("C:\/Users\/s1301\/Documents\/456.csv",encoding='utf-8')
 # df = pd.read_csv(f,header=None, names=['kw', 'url'])
-# df = pd.read_csv(f,header=None, names=['kw'])
-df = pd.read_csv(f,header=None, names=['prefix','id', 'positive','domain','rnd'])
+df = pd.read_csv(f,header=None, names=['kw'])
+# df = pd.read_csv(f,header=None, names=['prefix','id', 'positive','domain','rnd'])
 df=df.fillna('')
 # print(df)
 # url='fflc.tw'
 lst=[]
 for index,row in df.iterrows():
     # print(row)
-    prefix='"'+row['prefix']+'"'
-    # positive='"'+row['positive']+'"'
-    positive=row['positive']
-    domain='"'+row['domain']+'"'
-    rnd='"'+str(row['rnd'])+'"'
-    postfix='""'
-    id=row['id']
-    data = f'"id":{id},"prefix":{prefix},"domain":[{domain}],"postfix":{postfix},"positive":[{positive}],"rnd":[{rnd}]'
-    json='{'+data+'}'
-    print(json)
-    table.insert({'cust':client,'plan':'形象SEO','json':json})
-    # table.insert({'term':row['kw'],'client':client,'domain':domain})
+    # prefix='"'+row['prefix']+'"'
+    # # positive='"'+row['positive']+'"'
+    # positive=row['positive']
+    # domain='"'+row['domain']+'"'
+    # rnd='"'+str(row['rnd'])+'"'
+    # postfix='""'
+    # id=row['id']
+    # data = f'"id":{id},"prefix":{prefix},"domain":[{domain}],"postfix":{postfix},"positive":[{positive}],"rnd":[{rnd}]'
+    # json='{'+data+'}'
+    # print(json)
+    # table.insert({'cust':client,'plan':'形象SEO','json':json})
+    table.insert({'term':row['kw'],'client':client,'domain':domain})
     # table.insert({'term': row['kw'], 'client': client, 'url': row['url']})
 print(lst)
 {"prefix": "護佳", "postfix": "", "domain": ["www.hujiai-international.com"], "positive": ["細胞食物","紅蔘"], "rnd": [""]}

+ 3 - 1
SEO/ig_mysql.py

@@ -6,6 +6,8 @@ import sys
 import pprint
 import json
 import time
+import pymysql
+pymysql.install_as_MySQLdb()
 from instaloader import Instaloader, Hashtag
 #db = dataset.connect('sqlite:///:memory:)
 #db = dataset.connect('sqlite:///c:/tmp/ig.db')
@@ -30,7 +32,7 @@ def proc_tags(stmt):
 #    print(metadata)
 
 def search_hashtag(session, hashtag):
-    fw=codecs.open('c:/tmp/tags.txt','w','utf-8')
+    fw=codecs.open('C:\/Users\/s1301\/Downloads\/tags.txt','w','utf-8')
     jsonData = session.context.get_json(path="explore/tags/" + hashtag + "/", params={"__a": 1})
     fw.write(json.dumps(jsonData))
     fw.close()

+ 1 - 1
SEO/ranking_report.py

@@ -3,7 +3,7 @@ import dataset
 import pymysql
 pymysql.install_as_MySQLdb()
 
-name='plantA'
+name='美麗馨'
 date = '0216'
 
 

+ 71 - 0
monitor/GA4LN_base.py

@@ -0,0 +1,71 @@
+import os
+from datetime import datetime
+import requests
+from google.analytics.data_v1beta import BetaAnalyticsDataClient
+from google.analytics.data_v1beta.types import (
+    DateRange,
+    Dimension,
+    Metric,
+    MetricType,
+    RunReportRequest,
+)
+
+# IMPORTANT: Please set up GOOGLE_APPLICATION_CREDENTIALS through export (Bash) OR Environment Variables (Windows).
+# GOOGLE_APPLICATION_CREDENTIALS = "[path to credentials.json file]"
+
+# Insert PROPERTY IDs you want to track here.
+# Format: ["property_ID","property_name"]
+# KEEP THIS IN TUPLE FORM EVEN IF ONLY ONE DATA SOURCE IS USED !!
+# os.environ['GOOGLE_APPLICATION_CREDENTIALS']='C:\/Users\/s1301\/Downloads\/corded-velocity-301807-879b27e60620.json'+os.pathsep+'C:\/Users\/s1301\/Downloads\/corded-velocity-301807-c1a87c5dfc8d.json'
+property_id = [
+        ["290055766","Simpleprotein - GA4",{
+        "Authorization": "Bearer " + "DC7eiXkGoKzXcuCTuqCGmuNnDC15D3iv6E7tu5BAsUZ",
+        "Content-Type": "application/x-www-form-urlencoded"},"C:\/Users\/s1301\/Downloads\/corded-velocity-301807-879b27e60620.json"],
+        ["349445560","www.lisinbeauty.com",{"Authorization": "Bearer " + "4RO6ZOS4b7TkuqknajBPibTnOYnumHfwJvRzdZ3Bmq6",
+        "Content-Type": "application/x-www-form-urlencoded"},"C:\/Users\/s1301\/Downloads\/corded-velocity-301807-c1a87c5dfc8d.json"]] # CHANGE HERE
+# Insert PageView target here.
+pv_target = 0
+# Show whether target is achieved or not. Set to 1 to enable.
+show_target = 0
+
+# Enable/disable send to LINE Notify. Set to 1 to enable.
+send = 1
+# Insert destination LINE Group ID here.
+
+
+def send_msg(msg,lineid):
+    current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+    params = {"message": "Time: " + current_time + "\n" + msg}
+    # r = requests.post("https://notify-api.line.me/api/notify",headers=lineid, params=params)
+
+def run_report():
+
+    total = 0
+    message = ""
+    
+    for p in property_id:
+        os.environ['GOOGLE_APPLICATION_CREDENTIALS']=p[3]
+        client = BetaAnalyticsDataClient()
+        request = RunReportRequest(
+            property=f"properties/{p[0]}",
+            metrics=[Metric(name="screenPageViews")],
+            date_ranges=[DateRange(start_date="2023-02-19", end_date="2023-02-19")],
+        )
+        response = client.run_report(request)
+
+        for rowIdx, row in enumerate(response.rows):
+            for i, metric_value in enumerate(row.metric_values):
+                metric_name = response.metric_headers[i].name
+                viewcount = metric_value.value
+                message = message + (f"{p[1]} / {metric_name}: {viewcount}\n")
+                total = total + int(viewcount)
+        message = message + (f"Total views: {total}\n")
+        if show_target == 1:
+            if total >= pv_target:
+                message = message + ("Target reached\n")
+            else:
+                message = message + ("Target not reached\n")
+        print(message)
+        send_msg(message,p[2])
+
+run_report()

+ 73 - 0
monitor/GA4LN_icons.py

@@ -0,0 +1,73 @@
+from datetime import datetime
+import os
+import requests
+from google.analytics.data_v1beta import BetaAnalyticsDataClient
+from google.analytics.data_v1beta.types import (
+    DateRange,
+    Dimension,
+    Metric,
+    MetricType,
+    RunReportRequest,
+)
+
+# IMPORTANT: Please set up GOOGLE_APPLICATION_CREDENTIALS through export (Bash) OR Environment Variables (Windows).
+# GOOGLE_APPLICATION_CREDENTIALS = "[path to credentials.json file]"
+
+# Insert PROPERTY IDs you want to track here.
+# Format: ["property_ID","property_name"]
+# KEEP THIS IN TUPLE FORM EVEN IF ONLY ONE DATA SOURCE IS USED !!
+os.environ['GOOGLE_APPLICATION_CREDENTIALS']="C:\/Users\/s1301\/Downloads\/corded-velocity-301807-b52c79741854.json"
+# property_id = [["336444388","Icons_EN"],["336427321","Icons_ZH"]] # CHANGE HERE
+property_id = [["336444388","Icons_EN"]] # CHANGE HERE
+
+# Insert PageView target here.
+pv_target = 800
+# Show whether target is achieved or not. Set to 1 to enable.
+show_target = 0
+
+# Enable/disable send to LINE Notify. Set to 1 to enable.
+send = 1
+# Insert destination LINE Group ID here.
+LINE_GROUP_ID = 'zRyvl5OGuQZWpZqRmRsBT23qZ4ID9Ev6I7Jbz2gtpRU'
+
+# LINE Notify Header
+headers = {
+        "Authorization": "Bearer " + LINE_GROUP_ID,
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+def send_msg(msg):
+    current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+    params = {"message": "Time: " + current_time + "\n" + msg}
+    # r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
+
+def run_report():
+    client = BetaAnalyticsDataClient()
+    total = 0
+    message = ""
+    
+    for p in property_id:
+        request = RunReportRequest(
+            property=f"properties/{p[0]}",
+            metrics=[Metric(name="screenPageViews")],
+            date_ranges=[DateRange(start_date="today", end_date="today")],
+        )
+        response = client.run_report(request)
+
+        for rowIdx, row in enumerate(response.rows):
+            for i, metric_value in enumerate(row.metric_values):
+                metric_name = response.metric_headers[i].name
+                viewcount = metric_value.value
+                message = message + (f"{p[1]} / {metric_name}: {viewcount}\n")
+                total = total + int(viewcount)
+    message = message + (f"Total views: {total}\n")
+    if show_target == 1:
+        if total >= pv_target:
+            message = message + ("Target reached\n")
+        else:
+            message = message + ("Target not reached\n")
+    print(message)
+    if send == 1:
+        send_msg(message)
+
+run_report()

+ 2 - 0
monitor/notifyall.py

@@ -29,6 +29,8 @@ ga_info = {'有夠讚':['208868237',{
         "Content-Type": "application/x-www-form-urlencoded"},'C:\gitlab\kw_tools\monitor\corded-velocity-301807-f43006dd42c8.json'],
         '極簡乳清':['141324760',{"Authorization": "Bearer " + "DC7eiXkGoKzXcuCTuqCGmuNnDC15D3iv6E7tu5BAsUZ",
         "Content-Type": "application/x-www-form-urlencoded"},'C:\gitlab\kw_tools\monitor\corded-velocity-301807-879b27e60620.json'],
+        '美麗馨':['282939758',{"Authorization": "Bearer " + "4RO6ZOS4b7TkuqknajBPibTnOYnumHfwJvRzdZ3Bmq6",
+        "Content-Type": "application/x-www-form-urlencoded"},'C:\gitlab\kw_tools\monitor\corded-velocity-301807-c1a87c5dfc8d.json'],
 }
 
 def send_msg(viewid,header,key_file):