How to use the sopel.web.head function in sopel

To help you get started, we’ve selected a few sopel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sopel-irc / sopel-extras / oblique.py View on Github external
def service(bot, trigger, command, args):
    t = o.services[command]
    template = t.replace('${args}', urllib.quote(args.encode('utf-8'), ''))
    template = template.replace('${nick}', urllib.quote(trigger.nick, ''))
    uri = template.replace('${sender}', urllib.quote(trigger.sender, ''))

    info = web.head(uri)
    if isinstance(info, list):
        info = info[0]
    if not 'text/plain' in info.get('content-type', '').lower():
        return bot.reply("Sorry, the service didn't respond in plain text.")
    bytes = web.get(uri)
    lines = bytes.splitlines()
    if not lines:
        return bot.reply("Sorry, the service didn't respond any output.")
    bot.say(lines[0][:350])