當前位置: 首頁>>代碼示例>>Python>>正文


Python UtilBot.get_image_info方法代碼示例

本文整理匯總了Python中Core.Util.UtilBot.get_image_info方法的典型用法代碼示例。如果您正苦於以下問題:Python UtilBot.get_image_info方法的具體用法?Python UtilBot.get_image_info怎麽用?Python UtilBot.get_image_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Core.Util.UtilBot的用法示例。


在下文中一共展示了UtilBot.get_image_info方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: img

# 需要導入模塊: from Core.Util import UtilBot [as 別名]
# 或者: from Core.Util.UtilBot import get_image_info [as 別名]
def img(bot, event, *args):
    if len(args) > 0 and args[0] == 'list':
        aliases = UtilDB.get_list_of_aliases()
        segments = []
        for alias in aliases:
            segments.append(hangups.ChatMessageSegment(alias))
            segments.append(hangups.ChatMessageSegment('\n', hangups.SegmentType.LINE_BREAK))
        bot.send_message_segments(event.conv, segments)
    elif len(args) > 0 and args[0] == 'add':
        if len(args) < 3:
           bot.send_message(event.conv, "Error: not enough arguments")
           return
        # alias is all arguments except the first and last
        alias = ''.join(args[1:len(args)-1])
        # strip spaces and non-alphanumeric characters
        alias = ''.join(filter(str.isalnum, alias))
        alias = alias.lower()
        url = args[len(args)-1]
        if UtilDB.get_urls_for_alias(alias) is not None:
            bot.send_message(event.conv, "Error: that alias already exists")
            return
        print(str(is_valid_url(url)))
        if not is_valid_url(url):
            bot.send_message(event.conv, "Error: invalid URL")
            return
        UtilDB.set_alias_for_url(url, alias)
        bot.send_message(event.conv, "Alias {alias} saved with URL {url}".format(alias=alias,url=url))
#no special arguments
    elif len(args) > 0:
        url = args[0]
        is_alias = False
        alias = ''.join(args)
        # strip spaces and non-alphanumeric characters
        alias = ''.join(filter(str.isalnum, alias))
        alias = alias.lower()
        alias_url_list = UtilDB.get_urls_for_alias(alias)
        if alias_url_list is not None:
            random_url = random.choice(alias_url_list)
            if random_url is not None:
                url = random_url
                is_alias = True
        image_id_list = UtilDB.get_imageids_for_alias(alias)
        image_id = None
        if image_id_list is not None:
            image_id = random.choice(image_id_list)
            is_alias = True
        if not is_valid_url(url):
            url = 'http://' + url
            if not is_valid_url(url) and image_id is None:
                bot.send_message(event.conv, "Error: invalid alias or URL.")
                return            
        if image_id is None:
            image_id = UtilDB.get_imageid_for_url(url)
        desc = None
        if not is_alias:
            image_info = UtilBot.get_image_info(url)
            url, desc = image_info
        if desc is None and not is_alias:
            desc = ' '.join(args[1:])
        print(image_id)
        if image_id is None:
            filename = UtilBot.download_image(url, 'images', False)
            image_id = yield from UtilBot.upload_image(bot, filename)
            UtilDB.set_imageid_for_url(url, image_id)
            os.remove(filename)
        bot.send_message_segments(event.conv,
            [hangups.ChatMessageSegment(desc)] if desc else None,
            image_id)
開發者ID:gamecheet,項目名稱:HangoutsBot,代碼行數:70,代碼來源:CustomCommands.py


注:本文中的Core.Util.UtilBot.get_image_info方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。