zooeytsai 2 年 前
コミット
0b33de2d50
1 ファイル変更84 行追加0 行削除
  1. 84 0
      choozmo/gsc_tree2.py

+ 84 - 0
choozmo/gsc_tree2.py

@@ -0,0 +1,84 @@
+import searchconsole
+import dataset
+import os
+import networkx as nx
+from pyvis.network import Network
+
+
+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')
+    webproperty = account['https://bennis.com.tw/']
+    print(webproperty)
+    report = webproperty.query.range('today', days=-2).dimension('query').get()
+    # 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 'hhh.com.tw/designers/cases/' not in r[0]:
+            continue
+        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')
+
+    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()