bhouse_lib.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. import traceback
  2. import copy
  3. import operator
  4. import codecs
  5. import sys
  6. import os
  7. import searchconsole
  8. #account = searchconsole.authenticate(client_config='c:/keys/service/client_secret.json',credentials='c:/keys/service/credentials.json')
  9. account = searchconsole.authenticate(client_config='data/client_secret.json',credentials='data/credentials.json')
  10. # query, clicks, impressions, ctr, position
  11. def get_monthly_report(monthnum):
  12. webproperty = account['https://bhouse.com.tw/']
  13. #report=webproperty.query.range('2021-01-01', '2020-01-02').dimension('page','query').get()
  14. #report=webproperty.query.range('2021-01-01', '2020-04-01').dimension('query').get()
  15. #report=webproperty.query.range('today', days=-7).dimension('query').get()
  16. report=webproperty.query.range('today', months=monthnum).dimension('query').get()
  17. results=[]
  18. for r in report:
  19. results.append([r[0],r[1],r[2],r[3],float(r[4])])
  20. return results
  21. # for r in report:
  22. # print(r)
  23. # print(r[1])
  24. # print(r[4])