gsc_exp_designers.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import traceback
  2. import dataset
  3. import codecs
  4. import sys
  5. import pickle
  6. import os
  7. import searchconsole
  8. #db = dataset.connect('mysql://choozmo:pAssw0rd@127.0.0.1:3306/hhh?charset=utf8mb4')
  9. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  10. db.begin()
  11. #db = dataset.connect('sqlite:///:memory:')
  12. table=db['gsc_designers']
  13. #pname='korea'
  14. rid=0
  15. def checkig():
  16. global instl
  17. global table
  18. global pname
  19. global rid
  20. lst=[]
  21. cntdict={}
  22. codelist={}
  23. idx=0
  24. flag_break=False
  25. fname=os.path.abspath(__file__)
  26. elmts=fname.split(os.path.sep)
  27. path2=os.path.sep.join(elmts[0:-1])
  28. keysdir=path2+os.path.sep+'../keys'+os.path.sep
  29. # account = searchconsole.authenticate(client_config='c:/keys/client_secret.json',credentials='c:/keys/credentials.json')
  30. account = searchconsole.authenticate(client_config=keysdir+'client_secret.json',credentials=keysdir+'credentials.json')
  31. # webproperty = account['https://ipromise.com.tw/']
  32. # webproperty = account['https://'+pname+'.face8ook.org/']
  33. # webproperty = account['https://www.damanwoo.com/']
  34. webproperty = account['https://hhh.com.tw/']
  35. # report=webproperty.query.range('2021-03-01', '2021-06-17').dimension('page','query').get()
  36. # report=webproperty.query.range('2021-06-01', '2021-06-17').dimension('page','query').get()
  37. # report=webproperty.query.range('2020-06-01', '2021-06-22').dimension('page','query').filter('page', '/designers/cases/(491|31|293|278|31|24|594|356|307|491|33|385)', 'equals').get()
  38. # report=webproperty.query.range('2020-03-01', '2021-06-22').dimension('page','query').filter('page', '/designers/cases/'+pgnum, 'contains').get()
  39. # report=webproperty.query.range('2020-03-01', '2021-06-22').dimension('page','query').filter('page', '/designers/cases/'+pgnum, 'contains').get()
  40. # report=webproperty.query.range('2020-03-01', '2021-06-24').dimension('page','query').get()
  41. report=webproperty.query.range('2020-06-01', '2021-06-26').dimension('page','query').filter('page', '/designers/cases/', 'contains').get()
  42. result=[]
  43. for r in report.rows:
  44. entry={'page':r[0],'query':r[1]}
  45. result.append(entry)
  46. for r in result:
  47. table.insert(r)
  48. db.commit()
  49. r=checkig()