本文整理汇总了Python中Search.get_engine方法的典型用法代码示例。如果您正苦于以下问题:Python Search.get_engine方法的具体用法?Python Search.get_engine怎么用?Python Search.get_engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search.get_engine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Search [as 别名]
# 或者: from Search import get_engine [as 别名]
def main(argv):
"""
main(argv)
The entry point of the application
The input format should be: <API key> <infobox/question> <query>
"""
# API key
if argv[0] == 'test':
# Use the default key
api_key = 'AIzaSyBgfj3L8cqcu6OEd21JkQcHhBQJA6jUOXo'
else:
api_key = argv[0]
# Source: normal, file, or interact
if argv[1] == 'normal' or argv[1] == 'file' or argv[1] == 'interact':
source = argv[1]
else:
print 'Source should be \"normal\", \"file\", or \"interact\"'
return
# Mode: infobox or question
if source != 'interact':
if argv[2] == 'infobox' or argv[2] == 'question':
mode = argv[2]
else:
print 'Type should be either \"infobox\" or \"question\"'
return
# Get the search engine object with the given API key
se = Search.get_engine(api_key)
if source == 'normal':
query = ' '.join(argv[3:])
if mode == 'question':
question(se, query)
else:
infobox(se, query)
elif source == 'file':
qfile = open(argv[3], 'r')
for line in qfile:
if line.endswith('\n'):
line = line[0:-1]
if mode == 'question':
question(se, line)
else:
infobox(se, line)
else: # Interact
query = ''
while True:
try:
query = raw_input('Anything curious? ')
print 'Searching...'
if query.endswith('?'):
question(se, query)
else:
infobox(se, query)
except KeyboardInterrupt:
print 'Bye~'
break