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')
account = searchconsole.authenticate(client_config='data/client_secret.json',credentials='data/credentials.json')

# query, clicks, impressions, ctr, position
def get_monthly_report(monthnum):
    webproperty = account['https://bhouse.com.tw/']
    #report=webproperty.query.range('2021-01-01', '2020-01-02').dimension('page','query').get()
    #report=webproperty.query.range('2021-01-01', '2020-04-01').dimension('query').get()
    #report=webproperty.query.range('today', days=-7).dimension('query').get()
    report=webproperty.query.range('today', months=monthnum).dimension('query').get()
    results=[]
    for r in report:
        results.append([r[0],r[1],r[2],r[3],float(r[4])])
    return results

#    for r in report:
#        print(r)
#        print(r[1])
#        print(r[4])

