本文整理汇总了Python中Core.Util.UtilBot.is_integer方法的典型用法代码示例。如果您正苦于以下问题:Python UtilBot.is_integer方法的具体用法?Python UtilBot.is_integer怎么用?Python UtilBot.is_integer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core.Util.UtilBot
的用法示例。
在下文中一共展示了UtilBot.is_integer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: imagesearch
# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import is_integer [as 别名]
def imagesearch(bot, event, *args):
num_requested = 0
if len(args) == 0:
bot.send_message(event.conv, "Error: requires more than 0 arguments.")
return
else:
if args[-1][0] == '@' and UtilBot.is_integer(args[-1][1:]):
# we subtract one here because image #1 is the 0 item in the list
num_requested = int(args[-1][1:]) - 1
args = args[:-1]
if num_requested > 7 or num_requested < 0:
bot.send_message(event.conv,
"Error: result number must be between 1 and 8.")
return
query = ' '.join(args)
url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&' \
+ parse.urlencode({'q': query})
resp = request.urlopen(url)
image_json = json.loads(resp.read().decode())
url = image_json['responseData']['results'][num_requested]['unescapedUrl']
yield from send_image(bot, event, url)