本文整理汇总了Python中sopel.web.quote函数的典型用法代码示例。如果您正苦于以下问题:Python quote函数的具体用法?Python quote怎么用?Python quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quote函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: len
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
try:
recent_track = json.loads(recent_page)['recenttracks']['track'][0]
except KeyError:
willie.say("Couldn't find user")
sys.exit(0)
#artist and track name pulled from recent_track
quoted_artist = web.quote(recent_track['artist']['#text'])
quoted_track = web.quote(recent_track['name'])
#json formatted track info
trackinfo_page = urllib.urlopen("http://ws.audioscrobbler.com/2.0/?method=track.getInfo&artist=%s&track=%s&username=%s&api_key=782c02b1c96ae181d83850f050509103&format=json" % (quoted_artist, quoted_track, quoted_user))
#track playcount and loved stats
loved = 0
try:
trackinfo = json.loads(trackinfo_page.read())['track']
playcount = trackinfo['userplaycount']
loved = int(trackinfo['userloved'])
except KeyError:
playcount = "unknown"
album = '(' + recent_track['album']['#text'] + ') '
if len(recent_track['album']['#text']) == 0:
album = ''
开发者ID:blancNoir,项目名称:sopel,代码行数:30,代码来源:lastfm.py
示例17: wa_query
def wa_query(bot, trigger):
if not trigger.group(2):
return bot.say('[W|A] You must provide a query')
elif not bot.config.wolfram.app_id:
return bot.say('[W|A] Wolfram|Alpha API app ID not configured.')
client = wolframalpha.Client(bot.config.wolfram.app_id)
try:
result = client.query(trigger.group(2))
except Exception as e:
return bot.say('[W|A] An error occurred ({})'.format(e.message))
for pod in result.pods:
if pod.id not in output_ids:
continue
return bot.say('[W|A] {}: {}'.format(pod.title, pod.text))
if len(result.pods) > 0:
return bot.say('[W|A] No text-representable result found, see http://wolframalpha.com/input/?i={}'.format(web.quote(trigger.group(2))))
return bot.say('[W|A] No results found.')
开发者ID:Dropsik,项目名称:sopel-extras,代码行数:21,代码来源:wolfram.py
示例18: googleit
def googleit(bot, trigger):
"""Let me just... google that for you."""
# No input
if not trigger.group(2):
return bot.say('https://www.google.com/')
bot.say('https://lmgtfy.com/?q=' + quote(trigger.group(2).replace(' ', '+'), '+'))
开发者ID:neonobjclash,项目名称:sopel,代码行数:6,代码来源:lmgtfy.py
示例19: shorten_url
def shorten_url(url):
try:
res, headers = web.post('http://git.io', 'url=' + web.quote(url), return_headers=True)
return headers['location']
except:
return url
开发者ID:CoRD-Dev,项目名称:flutterfuck-github,代码行数:6,代码来源:formatting.py
示例20: wa_query
def wa_query(app_id, query, units='metric'):
if not app_id:
return 'Wolfram|Alpha API app ID not provided.'
client = wolframalpha.Client(app_id)
query = query.encode('utf-8').strip()
params = (
('format', 'plaintext'),
('units', units),
)
try: # Remove this mess for the next bump after 0.4
try: # wolframalpha 3.x supports extra stuff
result = client.query(input=query, params=params) # This is the only necessary line post-0.4
except TypeError: # fall back to query-only for 2.x
try:
result = client.query(query)
except:
raise # send any exceptions to the outer level
except:
raise # ditto; the 0.4 mess ends here
except AssertionError:
return 'Temporary API issue. Try again in a moment.'
except Exception as e:
return 'Query failed: {} ({})'.format(type(e).__name__, e.message or 'Unknown error, try again!')
num_results = 0
try: # try wolframalpha 3.x way
num_results = int(result['@numpods'])
except TypeError: # fall back to wolframalpha 2.x way
num_results = len(result.pods)
finally:
if num_results == 0:
return 'No results found.'
texts = []
try:
for pod in result.pods:
try:
texts.append(pod.text)
except AttributeError:
pass # pod with no text; skip it
except Exception:
raise # raise unexpected exceptions to outer try for bug reports
if len(texts) >= 2:
break # len() is O(1); this cheaply avoids copying more strings than needed
except Exception as e:
return 'Unhandled {}; please report this query ("{}") at https://dgw.me/wabug'.format(type(e).__name__, query)
try:
input, output = texts[0], texts[1]
except IndexError:
return 'No text-representable result found; see http://wolframalpha.com/input/?i={}'.format(web.quote(query))
if not output:
return input
return '{} = {}'.format(input, output)
开发者ID:dgw,项目名称:sopel-wolfram,代码行数:56,代码来源:wolfram.py
注:本文中的sopel.web.quote函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论