How to use the sopel.web 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 mappings(uri):
    result = {}
    bytes = web.get(uri)
    for item in r_item.findall(bytes):
        item = r_tag.sub('', item).strip(' \t\r\n')
        if not ' ' in item:
            continue

        command, template = item.split(' ', 1)
        if not command.isalnum():
            continue
        if not template.startswith('http://'):
            continue
        result[command] = template.replace('&', '&')
    return result
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])
github sopel-irc / sopel-extras / imgur.py View on Github external
def request(self, input):
        """
        Sends a request to the API. Only publicly available data is accessible.
        Returns data as JSON.
        """
        headers = {'Authorization': 'Client-ID ' + self.client_id,
                   'Accept': 'application/json'}
        request = web.get(self.api_url + input, headers=headers)
        #FIXME: raise for status
        return json.loads(request)