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


Python web.quote函数代码示例

本文整理汇总了Python中sopel.web.quote函数的典型用法代码示例。如果您正苦于以下问题:Python quote函数的具体用法?Python quote怎么用?Python quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: etymology

def etymology(word):
    # @@ <nsh> sbp, would it be possible to have a flag for .ety to get 2nd/etc
    # entries? - http://swhack.com/logs/2006-07-19#T15-05-29

    if len(word) > 25:
        raise ValueError("Word too long: %s[…]" % word[:10])

    ety = get(ETYURI % web.quote(word))
    if ety.status_code != 200:
        return None

    # Let's find it
    start = ety.text.find("word__defination")
    start = ety.text.find("<p>", start)
    stop = ety.text.find("</p>", start)
    sentence = ety.text[start + 3:stop]
    # Clean up
    sentence = unescape(sentence)
    sentence = sub('<[^<]+?>', '', sentence)

    maxlength = 275
    if len(sentence) > maxlength:
        sentence = sentence[:maxlength]
        words = sentence[:-5].split(' ')
        words.pop()
        sentence = ' '.join(words) + ' […]'

    sentence = '"' + sentence.replace('"', "'") + '"'
    return sentence + ' - ' + (ETYURI % web.quote(word))
开发者ID:neonobjclash,项目名称:sopel,代码行数:29,代码来源:etymology.py

示例2: wikt

def wikt(word):
    bytes = web.get(uri % web.quote(word))
    bytes = r_ul.sub('', bytes)

    mode = None
    etymology = None
    definitions = {}
    for line in bytes.splitlines():
        if 'id="Etymology"' in line:
            mode = 'etymology'
        elif 'id="Noun"' in line:
            mode = 'noun'
        elif 'id="Verb"' in line:
            mode = 'verb'
        elif 'id="Adjective"' in line:
            mode = 'adjective'
        elif 'id="Adverb"' in line:
            mode = 'adverb'
        elif 'id="Interjection"' in line:
            mode = 'interjection'
        elif 'id="Particle"' in line:
            mode = 'particle'
        elif 'id="Preposition"' in line:
            mode = 'preposition'
        elif 'id="' in line:
            mode = None

        elif (mode == 'etmyology') and ('<p>' in line):
            etymology = text(line)
        elif (mode is not None) and ('<li>' in line):
            definitions.setdefault(mode, []).append(text(line))

        if '<hr' in line:
            break
    return etymology, definitions
开发者ID:dasu,项目名称:sopel,代码行数:35,代码来源:wiktionary.py

示例3: get_np_info

def get_np_info(username):
    username = web.quote(username)
    api_key = "782c02b1c96ae181d83850f050509103"
    recent_tracks = web.get("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&format=json&user=%s&api_key=%s" % (username, api_key))

    #now playing track, or most recently scrobbled track
    now_playing = json.loads(recent_tracks)

    # if the user does not exist
    if 'recenttracks' not in now_playing:
        return None

    now_playing = now_playing['recenttracks']['track'][0]

    track = now_playing['name']
    album = now_playing['album']['#text']
    artist = now_playing['artist']['#text']

    # why the fuck doesnt this work with web.get() ???
    track_page = urllib.request.urlopen("http://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json&artist=%s&track=%s&username=%s&api_key=%s" % (web.quote(artist), web.quote(track), username, api_key))
    track_info = json.loads(track_page.read().decode())['track']
    user_playcount = "0"
    if 'userplaycount' in track_info:
        user_playcount = track_info['userplaycount']
    user_loved = False
    if int(track_info['userloved']) > 0:
        user_loved = True

    return {"track": track, "album": album, "artist": artist, "user_playcount": user_playcount, "user_loved": user_loved}
开发者ID:arza-zara,项目名称:Sopel-modules,代码行数:29,代码来源:lastfm.py

示例4: logHTML_end

def logHTML_end(channel):
    logfile = codecs.open(meeting_log_path + channel + '/' + figure_logfile_name(channel) + '.html', 'a', encoding='utf-8')
    current_time = time.strftime('%H:%M:%S', time.gmtime())
    logfile.write('</ul>\n<h4>Meeting ended at %s UTC</h4>\n' % current_time)
    plainlog_url = meeting_log_baseurl + quote(channel + '/' + figure_logfile_name(channel) + '.log')
    logfile.write('<a href="%s">Full log</a>' % plainlog_url)
    logfile.write('\n</body>\n</html>')
    logfile.close()
开发者ID:daniellawrence,项目名称:sopel,代码行数:8,代码来源:meetbot.py

示例5: logHTML_end

def logHTML_end(channel):
    logfile = codecs.open(
        meeting_log_path + channel + "/" + figure_logfile_name(channel) + ".html", "a", encoding="utf-8"
    )
    current_time = time.strftime("%H:%M:%S", time.gmtime())
    logfile.write("</ul>\n<h4>Meeting ended at %s UTC</h4>\n" % current_time)
    plainlog_url = meeting_log_baseurl + quote(channel + "/" + figure_logfile_name(channel) + ".log")
    logfile.write('<a href="%s">Full log</a>' % plainlog_url)
    logfile.write("\n</body>\n</html>")
    logfile.close()
开发者ID:reverieeee,项目名称:sopel,代码行数:10,代码来源:meetbot.py

示例6: f_etymology

def f_etymology(bot, trigger):
    """Look up the etymology of a word"""
    word = trigger.group(2)

    try:
        result = etymology(word)
    except IOError:
        msg = "Can't connect to etymonline.com (%s)" % (ETYURI % web.quote(word))
        bot.msg(trigger.sender, msg)
        return NOLIMIT
    except (AttributeError, TypeError):
        result = None
    except ValueError as ve:
        result = str(ve)

    if result is not None:
        bot.msg(trigger.sender, result)
    else:
        uri = ETYSEARCH % web.quote(word)
        msg = 'Can\'t find the etymology for "%s". Try %s' % (word, uri)
        bot.msg(trigger.sender, msg)
        return NOLIMIT
开发者ID:neonobjclash,项目名称:sopel,代码行数:22,代码来源:etymology.py

示例7: py

def py(bot, trigger):
    """Evaluate a Python expression."""
    if not trigger.group(2):
        return bot.say("Need an expression to evaluate")

    query = trigger.group(2)
    uri = BASE_TUMBOLIA_URI + 'py/'
    answer = web.get(uri + web.quote(query))
    if answer:
        #bot.say can potentially lead to 3rd party commands triggering.
        bot.reply(answer)
    else:
        bot.reply('Sorry, no result.')
开发者ID:ctburley,项目名称:sopel,代码行数:13,代码来源:calc.py

示例8: fucking_weather

def fucking_weather(bot, trigger):
    text = trigger.group(2)
    if not text:
        bot.reply("INVALID FUCKING PLACE. PLEASE ENTER A FUCKING ZIP CODE, OR A FUCKING CITY-STATE PAIR.")
        return
    text = web.quote(text)
    page = web.get("http://thefuckingweather.com/Where/%s" % (text))
    re_mark = re.compile('<p class="remark jsRemark">(.*?)</p>')
    results = re_mark.findall(page)
    if results:
        bot.reply(results[0])
    else:
        bot.reply("I CAN'T GET THE FUCKING WEATHER.")
        return bot.NOLIMIT
开发者ID:AurorasAura,项目名称:AuraBot,代码行数:14,代码来源:fuckingweather.py

示例9: lastfm

def lastfm(willie, trigger):
    user = ''
    if trigger.group(2):
        user = trigger.group(2).replace("@", trigger.nick)
    if not (user and user != ''):
        user = willie.db.get_nick_value(trigger.nick, 'lastfm_user')
        if not user:
            willie.reply("Invalid username given or no username set. Use .fmset to set a username.")
            return
    #username variable prepared for insertion into REST string
    user = user.lower()
    quoted_user = web.quote(user)
    #json formatted output for recent track
    try:
        recent_page = web.get("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=%s&api_key=782c02b1c96ae181d83850f050509103&format=json" % (quoted_user))
    except Exception, e:
        willie.say("last.fm is currently having technical difficulties. See .fmstatus for more information.")
        return
开发者ID:blancNoir,项目名称:sopel,代码行数:18,代码来源:lastfm.py

示例10: nowplaying

def nowplaying(bot, trigger):
    """displays the most recent track played by a given IRC nick."""
    output = ""
    notme = False
    if trigger.group(2):
        nick = re.match(r"^\S+", trigger.group(2)).group()
        notme = True
    else:
        nick = trigger.nick
    # check if nick is in room, if not, just use as lastfm username directly
    fmuser = bot.db.get_nick_value(nick, "lastfm_user")
    if not fmuser:
        bot.say("Use .fmset to associate a last.fm username with your IRC nick.")
        fmuser = nick
    try:
        recent_tracks = query_lastfm(bot, method="user.getrecenttracks", user=web.quote(fmuser))
    except Exception, e:
        bot.say("Couldn't contact last.fm :(")
        return
开发者ID:la11111,项目名称:willie-modules,代码行数:19,代码来源:lastfm.py

示例11: endmeeting

def endmeeting(bot, trigger):
    """
    End a meeting.\
    See [meetbot module usage]({% link _usage/meetbot-module.md %})
    """
    if not ismeetingrunning(trigger.sender):
        bot.say('Can\'t do that, start meeting first')
        return
    if not ischair(trigger.nick, trigger.sender):
        bot.say('Only meeting head or chairs can do that')
        return
    meeting_length = time.time() - meetings_dict[trigger.sender]['start']
    # TODO: Humanize time output
    bot.say(bold("Meeting ended!") + " total meeting length %d seconds" % meeting_length)
    logHTML_end(trigger.sender)
    htmllog_url = meeting_log_baseurl + quote(trigger.sender + '/' + figure_logfile_name(trigger.sender) + '.html')
    logplain('Meeting ended by %s, total meeting length %d seconds' % (trigger.nick, meeting_length), trigger.sender)
    bot.say('Meeting minutes: ' + htmllog_url)
    meetings_dict[trigger.sender] = Ddict(dict)
    del meeting_actions[trigger.sender]
开发者ID:sopel-irc,项目名称:sopel,代码行数:20,代码来源:meetbot.py

示例12: endmeeting

def endmeeting(bot, trigger):
    """
    End a meeting.
    https://github.com/embolalia/sopel/wiki/Using-the-meetbot-module
    """
    if not ismeetingrunning(trigger.sender):
        bot.say("Can't do that, start meeting first")
        return
    if not ischair(trigger.nick, trigger.sender):
        bot.say("Only meeting head or chairs can do that")
        return
    meeting_length = time.time() - meetings_dict[trigger.sender]["start"]
    # TODO: Humanize time output
    bot.say("Meeting ended! total meeting length %d seconds" % meeting_length)
    logHTML_end(trigger.sender)
    htmllog_url = meeting_log_baseurl + quote(trigger.sender + "/" + figure_logfile_name(trigger.sender) + ".html")
    logplain("Meeting ended by %s, total meeting length %d seconds" % (trigger.nick, meeting_length), trigger.sender)
    bot.say("Meeting minutes: " + htmllog_url)
    meetings_dict[trigger.sender] = Ddict(dict)
    del meeting_actions[trigger.sender]
开发者ID:reverieeee,项目名称:sopel,代码行数:20,代码来源:meetbot.py

示例13: wikt

def wikt(word):
    bytes = requests.get(uri % web.quote(word)).text
    bytes = r_ul.sub('', bytes)

    mode = None
    etymology = None
    definitions = {}
    for line in bytes.splitlines():
        if 'id="Etymology"' in line:
            mode = 'etymology'
        elif 'id="Noun"' in line:
            mode = 'noun'
        elif 'id="Verb"' in line:
            mode = 'verb'
        elif 'id="Adjective"' in line:
            mode = 'adjective'
        elif 'id="Adverb"' in line:
            mode = 'adverb'
        elif 'id="Interjection"' in line:
            mode = 'interjection'
        elif 'id="Particle"' in line:
            mode = 'particle'
        elif 'id="Preposition"' in line:
            mode = 'preposition'
        elif 'id="Prefix"' in line:
            mode = 'prefix'
        elif 'id="Suffix"' in line:
            mode = 'suffix'
        # 'id="' can occur in definition lines <li> when <sup> tag is used for references;
        # make sure those are not excluded (see e.g., abecedarian).
        elif ('id="' in line) and ('<li>' not in line):
            mode = None

        elif (mode == 'etmyology') and ('<p>' in line):
            etymology = text(line)
        elif (mode is not None) and ('<li>' in line):
            definitions.setdefault(mode, []).append(text(line))

        if '<hr' in line:
            break
    return etymology, definitions
开发者ID:neonobjclash,项目名称:sopel,代码行数:41,代码来源:wiktionary.py

示例14: wa

def wa(bot, trigger):
    """Wolfram Alpha calculator"""
    if not trigger.group(2):
        return bot.reply("No search term.")
    query = trigger.group(2)
    uri = BASE_TUMBOLIA_URI + "wa/"
    try:
        answer = web.get(uri + web.quote(query.replace("+", "plus")), 45, dont_decode=True)
    except timeout as e:
        return bot.say("[WOLFRAM ERROR] Request timed out")
    if answer:
        answer = answer.decode("unicode_escape")
        answer = HTMLParser.HTMLParser().unescape(answer)
        # This might not work if there are more than one instance of escaped
        # unicode chars But so far I haven't seen any examples of such output
        # examples from Wolfram Alpha
        match = re.search("\\\:([0-9A-Fa-f]{4})", answer)
        if match is not None:
            char_code = match.group(1)
            char = unichr(int(char_code, 16))
            answer = answer.replace("\:" + char_code, char)
        waOutputArray = answer.split(";")
        if len(waOutputArray) < 2:
            if answer.strip() == "Couldn't grab results from json stringified precioussss.":
                # Answer isn't given in an IRC-able format, just link to it.
                bot.say(
                    "[WOLFRAM]Couldn't display answer, try http://www.wolframalpha.com/input/?i="
                    + query.replace(" ", "+")
                )
            else:
                bot.say("[WOLFRAM ERROR]" + answer)
        else:

            bot.say("[WOLFRAM] " + waOutputArray[0] + " = " + waOutputArray[1])
        waOutputArray = []
    else:
        bot.reply("Sorry, no result.")
开发者ID:reverieeee,项目名称:sopel,代码行数:37,代码来源:calc.py

示例15: wa

def wa(bot, trigger):
    """Wolfram Alpha calculator"""
    if not trigger.group(2):
        return bot.reply("No search term.")
    query = trigger.group(2)
    uri = 'http://tumbolia-hrd.appspot.com/wa/'
    try:
        answer = web.get(uri + web.quote(query.replace('+', 'plus')), 45,
                         dont_decode=True)
    except timeout as e:
        return bot.say('[WOLFRAM ERROR] Request timed out')
    if answer:
        answer = answer.decode('unicode_escape')
        answer = HTMLParser.HTMLParser().unescape(answer)
        # This might not work if there are more than one instance of escaped
        # unicode chars But so far I haven't seen any examples of such output
        # examples from Wolfram Alpha
        match = re.search('\\\:([0-9A-Fa-f]{4})', answer)
        if match is not None:
            char_code = match.group(1)
            char = unichr(int(char_code, 16))
            answer = answer.replace('\:' + char_code, char)
        waOutputArray = answer.split(";")
        if(len(waOutputArray) < 2):
            if(answer.strip() == "Couldn't grab results from json stringified precioussss."):
                # Answer isn't given in an IRC-able format, just link to it.
                bot.say('[WOLFRAM]Couldn\'t display answer, try http://www.wolframalpha.com/input/?i=' + query.replace(' ', '+'))
            else:
                bot.say('[WOLFRAM ERROR]' + answer)
        else:

            bot.say('[WOLFRAM] ' + waOutputArray[0] + " = "
                    + waOutputArray[1])
        waOutputArray = []
    else:
        bot.reply('Sorry, no result.')
开发者ID:mvk,项目名称:sopel,代码行数:36,代码来源:calc.py


注:本文中的sopel.web.quote函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。