当前位置: 首页>>代码示例>>Python>>正文


Python UtilBot.upload_image方法代码示例

本文整理汇总了Python中Core.Util.UtilBot.upload_image方法的典型用法代码示例。如果您正苦于以下问题:Python UtilBot.upload_image方法的具体用法?Python UtilBot.upload_image怎么用?Python UtilBot.upload_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Core.Util.UtilBot的用法示例。


在下文中一共展示了UtilBot.upload_image方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_webpage_screenshot

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [as 别名]
def send_webpage_screenshot(bot, event, url, viewportsize='1280x1024'):
    filename = 'screenie.png'

    cliprectsize = '0x0x' + viewportsize;

    try:
        cmd = ['capturejs',
               '--uri',
               url,
               '--viewportsize',
               viewportsize,
               '--output',
               filename,
               '--cliprect',
               cliprectsize]

        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        output = output.decode(encoding='UTF-8')
        if output != '':
            bot.send_message(event.conv, output)

        image_id = yield from UtilBot.upload_image(bot, filename)
        send_image(bot, event, image_id)
        os.remove(filename)
    except http.client.BadStatusLine as e:
        display.stop()
        bot.send_message(event.conv, 'Error: BadStatusLine')
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:29,代码来源:CustomCommands.py

示例2: load_aliased_images

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [as 别名]
def load_aliased_images(bot, event, *args):
    file_exception = False
    try:
        imageids_filename = 'imageids.json'
        imageids = json.loads(open(imageids_filename, encoding='utf-8').read(), encoding='utf-8')
    except IOError as e:
        if e.errno == errno.ENOENT:
            imageids = {}
        else:
           print('Exception:')
           print(str(e))
           file_exception = True
    # loop through values in image_aliases.json
    aliases = load_json('image_aliases.json')
    for v in aliases.values():
        print('V = ' + str(v))
        for url in v if not isinstance(v, str) else [v]:
            print('URL = ' + url)
            # if url is not in imageids, upload it and store filename,id
            image_id = imageids.get(url)
            if image_id is None:
                print('URL = ' + url)
                filename = UtilBot.download_image(url, 'images')
                image_id = yield from UtilBot.upload_image(bot, filename)
                if not file_exception:
                    imageids[url] = image_id
                    with open(imageids_filename, 'w') as f:
                        json.dump(imageids, f, indent=2, sort_keys=True)
                    os.remove(filename)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:31,代码来源:CustomCommands.py

示例3: load_images_from_folder

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [as 别名]
def load_images_from_folder(bot, event, *args):
    folder = args[0]
    # loop through folder
    for filename in glob(os.path.join('images', folder, '*')):
        # if filename not in imageids, upload it and store filename,id
        filetail = os.path.split(filename)[1]
        filehead = os.path.split(os.path.split(filename)[0])[1]
        filekey = os.path.join(filehead, filetail)
        print(filekey)
        image_id = UtilDB.get_imageid_for_filename(filekey)
        if image_id is None:
            bot.send_message(event.conv,
                             "Uploading {}".format(filekey))
            image_id = yield from UtilBot.upload_image(bot, filename)
            UtilDB.set_imageid_for_filename(filekey, image_id)
            ####os.remove(filename)
        UtilDB.set_alias_for_filename(filekey, folder)
    bot.send_message(event.conv, "Done.")
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:20,代码来源:CustomCommands.py

示例4: color

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [as 别名]
def color(bot, event, *args):
    filename = 'color.png'
    cmd = ['convert',
           '-size',
           '500x500',
           'xc:%s' % ' '.join(args),
           filename]
    try:
        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        output = output.decode(encoding='UTF-8')
        if output != '':
            bot.send_message(event.conv, output)
        image_id = yield from UtilBot.upload_image(bot, filename)
        send_image(bot, event, image_id)
        os.remove(filename)
    except subprocess.CalledProcessError as e:
        output = e.output.decode(encoding='UTF-8')
        if output != '':
            bot.send_message(event.conv, output)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:21,代码来源:CustomCommands.py

示例5: latex

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [as 别名]
def latex(bot, event, *args):
    if ''.join(args) == '?':
        segments = UtilBot.text_to_segments("""\
**LaTeX**
Usage: /latex <LaTeX code>
Purpose: Renders LaTeX code to an image and sends it
""")
        bot.send_message_segments(event.conv, segments)
    else:
        cmd = "texvc /tmp images '" + \
              ' '.join(args).replace("'", "'\\''") + \
              "' utf-8 'rgb 1.0 1.0 1.0'"
        print('args: ')
        print(cmd)
        output = subprocess.check_output(cmd, shell=True)
        output = output.decode(encoding='UTF-8')
        print(output)
        filename = output[1:33] + '.png'
        filename = os.path.join('images', filename)
        image_id = yield from UtilBot.upload_image(bot, filename)
        send_image(bot, event, image_id)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:23,代码来源:CustomCommands.py

示例6: greentext

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [as 别名]
def greentext(bot, event, *args):
    """
    **Greentext**
    Usage: /greentext <text>
    Purpose: makes your text green and adds an epic maymay arrow, add more maymay arrows for more fun
    """
    filename = 'greentext.png'
    message = ' '.join(args)
    if message[0] == '>':
        message = message[1:]
    message = message.replace('>', '\n>')
    message = '>' + message
    print(message)
    cmd = ['convert',
           '-size',
           '164x',
           '-font',
           '/usr/share/fonts/TTF/arial.ttf',
           '-pointsize',
           '13',
           '-fill',
           '#789922',
           '-background',
           '#ffffee',
           'caption:%s' % message,
           filename]
    try:
        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        output = output.decode(encoding='UTF-8')
        if output != '':
            bot.send_message(event.conv, output)
        image_id = yield from UtilBot.upload_image(bot, filename)
        send_image(bot, event, image_id)
        os.remove(filename)
    except subprocess.CalledProcessError as e:
        output = e.output.decode(encoding='UTF-8')
        if output != '':
            bot.send_message(event.conv, output)
开发者ID:gamecheet,项目名称:HangoutsBot,代码行数:40,代码来源:CustomCommands.py

示例7: img

# 需要导入模块: from Core.Util import UtilBot [as 别名]
# 或者: from Core.Util.UtilBot import upload_image [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.upload_image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。