I'm just started working with the Google Search Analytics API main sample for python.
I would like to go further ahead and pass static variables to sample_tools.init() instead of being asked for them in the command-line interface.
In which way can I add these parameters and pass to sample_tools.init()?
start_date = '2015-10-20' start_date = '2015-10-21' var_uri = 'http://www.example.com'
import argparse
import sys
from googleapiclient import sample_tools
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('property_uri', type=str,
help=('Site or app URI to query data for (including '
'trailing slash).'))
argparser.add_argument('start_date', type=str,
help=('Start date of the requested date range in '
'YYYY-MM-DD format.'))
argparser.add_argument('end_date', type=str,
help=('End date of the requested date range in '
'YYYY-MM-DD format.'))
def main(argv):
service, flags = sample_tools.init(
argv, 'webmasters', 'v3', __doc__, __file__, parents=[argparser],
scope='https://www.googleapis.com/auth/webmasters.readonly')
request = {
'startDate': flags.start_date,
'endDate': flags.end_date,
'dimensions': ['page', 'query'],
'rowLimit': 50
}
response = execute_request(service, flags.property_uri, request)
print_table(response, 'Top Queries')