Преглед изворни кода

Merge remote-tracking branch 'origin/master'

zooeytsai пре 2 година
родитељ
комит
6ca584aea2

+ 6 - 1
INNNews/general_clickbot.py

@@ -17,7 +17,7 @@ import time
 import traceback
 import sys
 import fire
-from INNNews import notifytest
+#from INNNews import notifytest
 
 db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
 table=db['general_log']
@@ -81,6 +81,11 @@ def run_once(q):
     result=[]
     options = webdriver.ChromeOptions()
     options.add_argument('--headless')
+
+    options.add_argument('--disable-dev-shm-usage')
+    options.add_argument('--no-sandbox')
+    options.add_argument('--remote-debugging-port=9222')
+
 #    options.add_argument("--user-agent=" +user_agent)
     options.add_argument("--incognito")
 

+ 121 - 0
INNNews/general_remote_click.py

@@ -0,0 +1,121 @@
+import time
+import json
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+import time
+import os
+import urllib.parse
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support import expected_conditions as EC
+import codecs
+import random
+import requests
+import datetime
+import dataset
+import time
+import traceback
+import sys
+import fire
+#from INNNews import notifytest
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+table=db['general_log']
+
+
+  
+driver=None
+headers = {
+        "Authorization": "Bearer " + "6SDULL1Ebklduc6TFxa97AFto5Sj21kyJ30CxiLiSoi",
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+
+
+def send_msg(kw):
+    params = {"message": "error: "+kw}  
+    r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
+
+
+def empty_query(q):
+    global driver
+    googleurl='https://www.google.com/search?q='+urllib.parse.quote(q)
+    driver.get(googleurl)
+    time.sleep(3)
+
+
+def process_query(qs):
+    q=qs[0]
+    domain=qs[1]
+    global driver
+    googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(urllib.parse.quote(q), 100,'zh-TW')
+    print(googleurl)
+    driver.get(googleurl)
+    time.sleep(6)
+
+    elmts=driver.find_elements(By.XPATH,"//div[@class='yuRUbf']/a")
+
+    idx=1
+    ranking=-1
+    print(len(elmts))
+#    driver.save_screenshot('c:/tmp/test.png')
+
+    for elmt in elmts:
+
+        href=elmt.get_attribute('href')
+        txt=elmt.text
+        if len(txt)>10:
+            if domain in href:
+                print('clicked....')
+                print(href)
+                print(txt)
+                print("ranking", idx)
+                table.insert({'kw':q,'domain':domain,'ranking':idx,'title':txt,'url':href,'dt':datetime.datetime.now()})
+                webdriver.ActionChains(driver).move_to_element(elmt).perform()
+                webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+                break
+        idx+=1
+
+def run_once(q):
+    global driver
+    result=[]
+    options = webdriver.ChromeOptions()
+    options.add_argument('--headless')
+
+    options.add_argument('--disable-dev-shm-usage')
+    options.add_argument('--no-sandbox')
+#    options.add_argument('--remote-debugging-port=9222')
+
+    epath=os.environ['WEBDRIVER']
+
+#    options.add_experimental_option("debuggerAddress", "192.168.192.45:9922")
+    options.add_experimental_option("debuggerAddress", q[2])
+
+#    options.add_argument("--user-agent=" +user_agent)
+    options.add_argument("--incognito")
+#    driver = webdriver.Chrome(executable_path=r'C:\portable\webdriver\chrome98\chromedriver.exe',options=options)
+    driver = webdriver.Chrome(executable_path=epath,options=options)
+
+    driver.delete_all_cookies()
+    driver.set_window_size(1400,1000)
+
+    print(q)
+    process_query(q)
+    time.sleep(3)
+    driver.quit()
+
+class JParams(object):
+
+  def get(self, kw,domain,address):
+    try:
+        print(kw)
+        print(domain)
+        run_once( (kw,domain,address)   )
+    except:
+        traceback.print_exc()
+        send_msg('SEO docker exception... stop')
+
+
+if __name__ == '__main__':
+  fire.Fire(JParams)
+

+ 53 - 0
INNNews/routine_click.py

@@ -0,0 +1,53 @@
+import time
+import json
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+import time
+import os
+import urllib.parse
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support import expected_conditions as EC
+import codecs
+import random
+import requests
+import datetime
+import dataset
+import time
+import traceback
+import sys
+import fire
+#from INNNews import notifytest
+
+
+probdict={}
+probdict[0]={'client':'hhh','domain':'hhh.com.tw'}
+probdict[1]={'client':'毛怪','domain':'beastparadise.net'}
+probdict[2]={'client':'清原','domain':'taroboba-yuan.com'}
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+
+prob=[0,0,0,0,1,1,2,2]
+idx=random.choice(prob)
+
+client=probdict[idx]['client']
+domain=probdict[idx]['domain']
+
+term=None
+address="192.168.192.45:9922"
+cursor=db.query('SELECT term FROM seo.selected_kw where client = "'+client+'" order by rand() limit 1')
+for c in cursor:
+    term=c['term']
+    break
+
+if os.name == 'nt':
+    py='python'
+else:
+    py='python3'
+
+
+#set WEBDRIVER=C:/portable/webdriver/chrome98/chromedriver.exe
+#os.system(py+' general_remote_click.py get --kw="'+term+'" --domain='+domain+' --address="'+address+'" --epath="C:/portable/webdriver/chrome98/chromedriver.exe"')
+os.system(py+' general_remote_click.py get --kw="'+term+'" --domain='+domain+' --address="'+address+'"')
+
+

+ 6 - 1
INNNews/run_sheet.py

@@ -18,4 +18,9 @@ js=r.get('innews_sheet')
 jsobj=json.loads(js)
 kw=random.choice(jsobj)
 print(kw['kw'])
-os.system('python general_clickbot.py get --kw="'+kw['kw']+'" --domain=innews.com.tw')
+if os.name == 'nt':
+    py='python'
+else:
+    py='python3'
+
+os.system(py+' general_clickbot.py get --kw="'+kw['kw']+'" --domain=innews.com.tw')

+ 108 - 0
SEO/general_clickjob.py

@@ -0,0 +1,108 @@
+import time
+import json
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+import time
+import os
+import urllib.parse
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support import expected_conditions as EC
+import codecs
+import random
+import requests
+import dataset
+import time
+import traceback
+import sys
+
+driver=None
+headers = {
+        "Authorization": "Bearer " + "t35vhZtWNgvDNWHc3DJh0OKll3mcB9GvC8K2EAkBug2",
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+
+
+def send_msg(kw):
+    params = {"message": "處理關鍵字: "+kw}  
+    r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
+
+
+def empty_query(q):
+    global driver
+    googleurl='https://www.google.com/search?q='+urllib.parse.quote(q)
+    driver.get(googleurl)
+    time.sleep(3)
+
+
+def process_query(qs):
+    q=qs[0]
+    domain=qs[1]
+    global driver
+    googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(urllib.parse.quote(q), 100,'zh-TW')
+    print(googleurl)
+    driver.get(googleurl)
+    time.sleep(6)
+
+    elmts=driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
+
+    idx=1
+    ranking=-1
+    print(len(elmts))
+#    driver.save_screenshot('c:/tmp/test.png')
+
+    for elmt in elmts:
+
+        href=elmt.get_attribute('href')
+        txt=elmt.text
+        if len(txt)>10:
+            if domain in href:
+                print('clicked....')
+                print(href)
+                print(txt)
+                webdriver.ActionChains(driver).move_to_element(elmt).perform()
+                webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
+                break
+
+
+def run_once(q):
+    global driver
+    result=[]
+    options = webdriver.ChromeOptions()
+    options.add_argument('--headless')
+#    options.add_argument("--user-agent=" +user_agent)
+    options.add_argument("--incognito")
+
+    driver = webdriver.Chrome(
+    options=options)
+
+    driver.delete_all_cookies()
+    driver.set_window_size(1400,1000)
+
+    print(q)
+    process_query(q)
+    time.sleep(3)
+    driver.quit()
+
+
+#lst=[{'kw':'幸福空間','domain':'hhh.com.tw','page':0}]
+lst=[]
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+
+cursor=db.query('select term,domain from selected_kw  order by rand()')
+
+for c in cursor:
+    lst.append(c)
+
+
+#for c in lst:
+while True:
+    try:
+        c=random.choice(lst)
+        run_once( (c['term'],c['domain'])   )
+    except:
+        traceback.print_exc()
+    sleepint=random.randint(320,520)
+    time.sleep(sleepint)
+

+ 8 - 0
console/google_status.py

@@ -0,0 +1,8 @@
+import dataset
+
+db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/google_poi?charset=utf8mb4')
+cursor=db.query("SELECT count(*) as cnt FROM google_poi.shop_list3;")
+
+for c in cursor:
+    print(c['cnt'])
+    break

+ 10 - 0
console/restart_seo_tiny_docker.py

@@ -0,0 +1,10 @@
+import rpyc
+import os
+conn = rpyc.classic.connect("192.168.192.45",18812)
+conn.execute('import os')
+ros = conn.modules.os
+ros.system('docker restart tiny1')
+#ros.system('docker restart 62eab82f7759') 
+#print('after restart')
+#time.sleep(11)
+#print('after wait')

+ 23 - 0
docker/alpine-chrome/Dockerfile

@@ -0,0 +1,23 @@
+FROM python:alpine3.14
+
+# update apk repo
+RUN echo "http://dl-4.alpinelinux.org/alpine/v3.14/main" >> /etc/apk/repositories && \
+    echo "http://dl-4.alpinelinux.org/alpine/v3.14/community" >> /etc/apk/repositories
+
+# install chromedriver
+RUN apk update
+RUN apk add build-base
+RUN apk add libffi-dev
+RUN apk add mariadb-dev
+RUN apk add chromium chromium-chromedriver
+RUN apk add tmux
+# upgrade pip
+RUN pip3 install --upgrade pip
+RUN pip3 install bs4
+RUN pip3 install selenium-wire 
+RUN pip3 install dataset
+RUN pip3 install mysqlclient
+RUN pip3 install selenium
+RUN pip3 install pandas
+RUN pip3 install pymysql
+RUN apk add bash

+ 7 - 0
docker/alpine-poi/Dockerfile

@@ -0,0 +1,7 @@
+FROM choozmodocker/alpine-basic:latest
+RUN pip3 install bs4
+RUN pip3 install selenium-wire 
+RUN pip3 install pandas
+RUN pip3 install pymysql
+RUN pip3 install requests
+ENTRYPOINT ["python3", "/app/run4.py"]

+ 20 - 6
tests/rpc_key_test.py

@@ -1,23 +1,30 @@
 import rpyc
 import time
 import schedule
-s1={'ip':'192.168.192.199','names':['poi1','poi2','poi3']} #MBA_HOME
-s2={'ip':'192.168.192.58','names':['poi1','poi2','poi3']} #RDP_HOME
+import traceback
+
+s1={'ip':'192.168.192.199','names':['poi1','poi2','poi3','poi4']} #MBA_HOME
+#s2={'ip':'192.168.192.58','names':['poi1','poi2','poi3']} #RDP_HOME
 s3={'ip':'192.168.192.146','names':['poi1','poi2']} #TOSHIBA
 s4={'ip':'192.168.192.45','names':['poi1','poi2']} #public1
 #s5={'ip':'192.168.192.156','names':['seo1','seo2']} #32g
-s5={'ip':'192.168.192.156','names':['poi1','poi2','poi3','poi4']} #32g
+s5={'ip':'192.168.192.156','names':['poi1','poi2','poi3','poi4','poi5','poi6']} #32g
 #s5={'ip':'192.168.192.156','names':['hhhclick1','hhhclick2','seo1','seo2']}
-s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3']} #64G
+s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14']} #64G
+s7={'ip':'192.168.192.139','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston1
+s8={'ip':'192.168.192.43','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston2
 
 #servers=[s1,s2,s4,s5,s6]
+servers=[s1,s3,s5,s6,s7,s8]
 
-servers=[s1,s2,s3,s4,s5,s6]
+#servers=[s1,s2,s3,s4,s5,s6]
 #conn = rpyc.ssl_connect("192.168.192.199", port = 18812, keyfile="c:/tmp/client.key",
 #                        certfile="c:/tmp/client.cer")
 
 def do_job():
     global servers
+    cnt=0
+
     for srv in servers:
         print(srv['ip'])
         conn=None
@@ -38,11 +45,18 @@ def do_job():
             if n not in cur_names:
                 print("calling: " +n)
                 ros.system('docker container restart '+n)
+            else:
+                cnt+=1
+        print('cnt='+str(cnt))
+    print('cnt='+str(cnt))
 
 do_job()
 schedule.every(3).minutes.do(do_job)
 
 while True:
-    schedule.run_pending()
+    try:
+        schedule.run_pending()
+    except:
+        traceback.print_exc()
     time.sleep(1)