123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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()
|