示例#1
0
def mw_info(bot, trigger, match=None):
    """Retrieves and outputs a snippet of the linked page."""
    if match.group(3):
        if match.group(3).startswith('cite_note-'):  # Don't bother trying to retrieve a snippet when cite-note is linked
            say_snippet(bot, trigger, match.group(1), unquote(match.group(2)), show_url=False)
        else:
            say_section(bot, trigger, match.group(1), unquote(match.group(2)), unquote(match.group(3)))
    else:
        say_snippet(bot, trigger, match.group(1), unquote(match.group(2)), show_url=False)
示例#2
0
文件: wikipedia.py 项目: r4f4/sopel
def mw_info(bot, trigger, match):
    """Retrieves and outputs a snippet from the linked page."""
    say_snippet(bot,
                trigger,
                match.group(1),
                unquote(match.group(2)),
                show_url=False)
示例#3
0
def duck_search(query):
    query = query.replace('!', '')
    base = 'https://duckduckgo.com/html/'
    parameters = {
        'kl': 'us-en',
        'q': query,
    }
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
    }
    bytes = requests.get(base, parameters, headers=headers).text
    if 'web-result' in bytes:  # filter out the adds on top of the page
        bytes = bytes.split('web-result')[1]
    m = r_duck.search(bytes)
    if m:
        unquoted_m = web.unquote(m.group(1))
        return web.decode(unquoted_m)
示例#4
0
def test_unquote(text, result):
    assert unquote(text) == result