在GoogleAppClient-Python中使用静态变量而不是argparse
我刚刚开始使用Google Search Analytics API main for python 我想更进一步,将静态变量传递给sample_tools.init(),而不是在命令行界面中要求它们 我可以用哪种方式添加这些参数并传递给示例_tools.init() 开始日期='2015-10-20'开始日期='2015-10-21'变量uri= ''在GoogleAppClient-Python中使用静态变量而不是argparse,python,google-search-api,Python,Google Search Api,我刚刚开始使用Google Search Analytics API main for python 我想更进一步,将静态变量传递给sample_tools.init(),而不是在命令行界面中要求它们 我可以用哪种方式添加这些参数并传递给示例_tools.init() 开始日期='2015-10-20'开始日期='2015-10-21'变量uri= '' 这很简单,我只是从数组中删除了argparser,并将其保留为空,然后定义变量 def main(argv): service, fl
这很简单,我只是从数组中删除了argparser,并将其保留为空,然后定义变量
def main(argv):
service, flags = sample_tools.init(
argv, 'webmasters', 'v3', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/webmasters.readonly')
start_date = datetime.datetime.strftime(
datetime.datetime.now() - datetime.timedelta(days=4), '%Y-%m-%d')
end_date = datetime.datetime.strftime(
datetime.datetime.now() - datetime.timedelta(days=3), '%Y-%m-%d')
property_uri = 'http://www.bmimedia.net'
#Create the request. Use the API tutorial to explain how the API works
request = {
'startDate': end_date,
'endDate': end_date,
'dimensions': ['page', 'query'],
'rowLimit': 10
}
response = execute_request(service, property_uri, request)
print_table(response, 'Top Queries', end_date)
甚至
argv
也可以被[]
替换,并且可以从sample\u tools.init
args中删除parents=[]
。
def main(argv):
service, flags = sample_tools.init(
argv, 'webmasters', 'v3', __doc__, __file__, parents=[],
scope='https://www.googleapis.com/auth/webmasters.readonly')
start_date = datetime.datetime.strftime(
datetime.datetime.now() - datetime.timedelta(days=4), '%Y-%m-%d')
end_date = datetime.datetime.strftime(
datetime.datetime.now() - datetime.timedelta(days=3), '%Y-%m-%d')
property_uri = 'http://www.bmimedia.net'
#Create the request. Use the API tutorial to explain how the API works
request = {
'startDate': end_date,
'endDate': end_date,
'dimensions': ['page', 'query'],
'rowLimit': 10
}
response = execute_request(service, property_uri, request)
print_table(response, 'Top Queries', end_date)