Browse Source

Merge remote-tracking branch 'origin/master'

zooeytsai 2 years ago
parent
commit
8fefdad61b
2 changed files with 193 additions and 0 deletions
  1. 110 0
      choozmo/gsc_tree3.py
  2. 83 0
      monitor/hhh2.py

+ 110 - 0
choozmo/gsc_tree3.py

@@ -0,0 +1,110 @@
+import searchconsole
+import dataset
+import os
+import networkx as nx
+from pyvis.network import Network
+import sys
+
+db = dataset.connect('sqlite:///:memory:')
+table=db['tmp']
+rid=0
+
+def checkig():
+    global instl
+    global table
+    global pname
+    global rid
+    lst=[]
+    cntdict={}
+    codelist={}
+    idx=0
+    flag_break=False
+
+    fname=os.path.abspath(__file__)
+    elmts=fname.split(os.path.sep)
+    path2=os.path.sep.join(elmts[0:-1])
+    keysdir=path2+os.path.sep+'../keys'+os.path.sep
+
+#    account = searchconsole.authenticate(client_config='/Users/zooeytsai/Downloads/client_secret4.json')
+
+#    account = searchconsole.authenticate(client_config='c:/keys/client_secret4.json',serialize='c:/keys/credentials20220524.json')
+    account = searchconsole.authenticate(client_config='c:/keys/client_secret4.json',credentials='c:/keys/credentials20220524.json')
+
+#    account = searchconsole.authenticate(client_config='c:/keys/client_secret.json',credentials='c:/keys/credentials.json')
+
+    import pprint
+    import codecs
+#    pprint.pprint(vars(account.service.sites))
+#    pprint.pprint(vars(account.service))
+    site_list = account.service.sites().list().execute()
+    print(site_list)
+#    print(account.service.sites().list())
+#    fw=codecs.open('c:/tmp/pprint.txt','w','utf-8')
+#    fw.write(pprint.pformat(vars(account)))
+#    fw.close()
+#    sys.exit()
+#  credentials='credentials.json'
+#    print(account.)
+
+#    webproperty = account['https://bennis.com.tw/']
+    webproperty = account['sc-domain:bennis.com.tw']
+
+
+    print(webproperty)
+#    report = webproperty.query.range('today', days=-7).dimension('query').get()
+    report=webproperty.query.range('today', days=-4).dimension('page','query').get()
+
+
+    print(report)
+
+    # report = webproperty.query.range('2022-05-20', '2022-05-23').dimension('page', 'query').get()
+#    account = searchconsole.authenticate(client_config='C:\\gitlab\\kw_tools\\kw_tools\\hhh\\keys\\client_secret.json',credentials='C:\\gitlab\\kw_tools\\kw_tools\\hhh\\keys\\credentials.json')
+    G = nx.Graph()
+
+#    webproperty = account['https://ipromise.com.tw/']
+#    webproperty = account['sc-domain:face8ook.org']
+#     webproperty = account['sc-domain:hhh.com.tw']
+
+
+    result=[]
+    rdict={}
+    total_idx=0
+
+    for r in report.rows:
+        if rdict.get(r[0]) is None:
+            total_idx+=1
+            rid=total_idx
+            rdict[r[0]]=rid
+        else:
+            rid=rdict[r[0]]
+        entry={'page':r[0],'query':r[1],'rid':rid}
+        result.append(entry)
+
+    print('list done')
+    print(result)
+    for r in result:
+        table.insert(r)
+    db.commit()
+    print('db done')
+
+#    cursor=db.query('select query as q,page as url,rid from tmp where rid in (select rid from (select rid,count(*) from tmp group by rid having count(*) > 2 and count(*) < 6) as tbl1) order by rid ')
+    cursor=db.query('select query as q,page as url,rid from tmp order by rid ')
+
+    riddict={}
+    prev=''
+    curnode=''
+    cururl=''
+
+    total_idx=0
+    for c in cursor:
+        G.add_edge(c['q'],c['rid'],weight=3,width=3,borderwidth=3)
+    remove=[]
+    G.remove_edges_from(nx.selfloop_edges(G))
+    G2=G
+    pyG = Network(height="600px", width="100%",bgcolor="#444444",font_color="white")
+
+    pyG.from_nx(G2)
+    pyG.show('news.html')
+
+
+r=checkig()

+ 83 - 0
monitor/hhh2.py

@@ -0,0 +1,83 @@
+import sys
+import codecs
+import traceback
+import requests
+import re
+import pandas as pd
+import random
+import urllib
+import json
+import gspread
+import datetime
+from gspread_pandas import Spread, Client
+from oauth2client.service_account import ServiceAccountCredentials
+import os
+import redis
+import time
+import fire
+import dataset
+import pymysql
+pymysql.install_as_MySQLdb()
+
+def run_once(pport, dockername):
+    db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
+    seeds=['室內 設計','室內設計','客廳 裝潢','裝潢','房間 設計','台北','台北 設計','台北 室內','台北  室內 設計','電視 牆','電視','裝潢 設計','裝潢 室內','室內 設計 費用','設計 費用','居家 空間 設計','居家 設計','居家 空間','空間 設計','衣魚','玄關設計','房間佈置','量子電視','小坪數裝潢','踢腳板','清潔劑','班傑明油漆','冰箱除臭']
+#    lst=[['衣櫃設計'],['磁磚尺寸'],['幸福空間設計'],['養魚風水'],['房間風水'],['衣魚'],['冰箱除臭'],['大腸鏡檢查費用'],['房間佈置'],['潮濕蟲漂白水'],['小坪數裝潢'],['幸福空間'],['衣櫃設計'],['門對門'],['玄關設計'],['幸福空間'],['幸福空間'],['衣魚有害嗎'],['幸福空間'],['幸福空間 稅']]
+#    lst=[['衣櫃設計'],['磁磚尺寸'],['幸福空間設計'],['養魚風水'],['房間風水'],['衣魚'],['冰箱除臭'],['大腸鏡檢查費用'],['房間佈置'],['潮濕蟲漂白水'],['小坪數裝潢'],['幸福空間'],['衣櫃設計'],['門對門'],['玄關設計'],['幸福空間'],['幸福空間'],['衣魚有害嗎'],['幸福空間'],['幸福空間 稅']]
+
+    lst=[]
+    for s in seeds:
+        lst.append([s+' 幸福'])
+        lst.append([s+' 幸福空間'])
+        lst.append([s+' 幸福 空間'])
+
+#    lst = [['幸福空間'],['開運植物  幸福空間'],['幸福 文化美藏'],['三井牙醫  幸福空間'],['現代混搭 幸福空間'],['簡單的事 幸福空間'],['古典風雅 幸福空間'],['木藝 幸福空間']]
+#    lst = [['幸福空間'],['開運植物  幸福空間'],['幸福 文化美藏'],['三井牙醫  幸福空間'],['現代混搭 幸福空間'],['簡單的事 幸福空間'],['古典風雅 幸福空間'],['木藝 幸福空間']]
+
+
+#    cursor = db.query('SELECT * FROM hhh.seo_designer order by rand() limit 40')
+    cursor = db.query('SELECT * FROM hhh.seo_designer order by rand() limit 1')
+
+    for c in cursor:
+
+        lst.append([c['kw']])
+
+    obj = random.choice(lst)
+    print(obj)
+    kw = obj[0]
+    domain = 'hhh.com.tw'
+    print(kw,domain)
+
+    s = f'python3 general_clickbot_hhh.py get --kw="{kw}" --domain="{domain}" --port={str(pport)}'
+
+    intval = os.system(f'python3 general_clickbot_hhh.py get --kw="{kw}" --domain="{domain}" --port="{str(pport)}"')
+    
+    print('執行genetal_clickbot')
+
+    if intval == -1:
+        print('-1')
+        sys.exit()
+
+
+class JParams(object):
+    
+    def get(self, port=9222):
+        while True:
+            try:
+                os.system('docker container restart tiny4')
+                os.system('docker container restart tiny5')
+                os.system('docker container restart tiny6')
+                time.sleep(1)
+                run_once(9925, 'tiny4')
+                run_once(9926, 'tiny5')
+                run_once(9927, 'tiny6')
+                time.sleep(20)
+
+            except:
+                os.system('docker container restart tiny4')
+                time.sleep(15)
+
+
+if __name__ == '__main__':
+    fire.Fire(JParams)
+