本文整理匯總了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