import traceback
import copy
import operator
import codecs
import sys
import os
import searchconsole

account = searchconsole.authenticate(client_config='c:/keys/service/client_secret.json',credentials='c:/keys/service/credentials.json')
webproperty = account['https://hhh.com.tw/']


#report=webproperty.query.range('2021-01-01', '2020-01-02').dimension('page','query').get()
report=webproperty.query.range('2021-01-01', '2020-05-04').dimension('query').filter('query', '裝修設計', 'contains').get()
total_pos=0
total_count=0
total_clicks=0
for r in report:
    print(r)
    query=r[0]
    clicks=r[1]
    impressions=r[2]
    ctr=r[3]
    position=r[4]
    total_clicks+=int(clicks)
    total_pos+=float(position)
    total_count+=1

print(total_pos/total_count)
print(total_clicks)
