本文整理汇总了Python中modules.unicode.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: load_db
def load_db():
""" load lines from find.txt to search_dict """
if not os.path.isfile("find.txt"):
f = open("find.txt", "w")
f.write("#test,yano,foobar\n")
f.close()
search_file = open("find.txt", "r")
lines = search_file.readlines()
search_file.close()
search_dict = dict()
for line in lines:
line = uc.decode(line)
line = uc.encode(line)
a = line.replace(r'\n', '')
new = a.split(r',')
if len(new) < 3: continue
channel = uc.encode(new[0])
nick = new[1]
if len(new) < 2: continue
if channel not in search_dict:
search_dict[channel] = dict()
if nick not in search_dict[channel]:
search_dict[channel][nick] = list()
if len(new) > 3:
result = ",".join(new[2:])
result = result.replace('\n','')
elif len(new) == 3:
result = new[-1]
if len(result) > 0:
result = result[:-1]
if result:
search_dict[channel][nick].append(uc.decode(result))
return search_dict
开发者ID:TRiGGER80,项目名称:jenni,代码行数:33,代码来源:find.py
示例2: rmuser
def rmuser(self, jenni, input, line):
if not input.admin:
return
if len(line) < 9:
jenni.reply("No input provided.")
return
line = line[8:].split()
channel = uc.encode((input.sender).lower())
nick = uc.encode(line[0]).lower()
def check(nick, channel):
nick = nick.lower()
channel = channel.lower()
if channel in self.scores_dict:
if nick in self.scores_dict[channel]:
del self.scores_dict[channel][nick]
return self.STRINGS["rmuser"].format(nick, channel)
else:
return self.STRINGS["nouser"].format(nick, channel)
else:
return self.STRINGS["nochan"].format(channel)
if len(line) == 1:
## .rmuser <nick>
result = check(nick, (input.sender).lower())
self.save()
elif len(line) == 2:
## .rumser <channel> <nick>
result = check(line[1], nick)
self.save()
jenni.say(result)
开发者ID:Jarada,项目名称:jenni,代码行数:32,代码来源:scores.py
示例3: setpoint
def setpoint(self, jenni, input, line):
if not input.admin:
return
line = line[10:].split()
if len(line) != 4:
return
channel = uc.encode(line[0]).lower()
nick = uc.encode(line[1]).lower()
try:
add = int(line[2])
sub = int(line[3])
except:
jenni.say(self.STRINGS["invalid"])
return
if add < 0 or sub < 0:
jenni.reply("You are doing it wrong.")
return
if channel not in self.scores_dict:
self.scores_dict[channel] = dict()
self.scores_dict[channel][nick] = [int(add), int(sub)]
self.save()
jenni.say(self.str_score(nick, channel))
开发者ID:Jarada,项目名称:jenni,代码行数:25,代码来源:scores.py
示例4: delquote
def delquote(code, input):
'''delquote <number> -- removes a given quote from the database. Can only be done by the owner of the bot.'''
text = input.group(2)
number = int()
try:
fn = open('quotes.txt', 'r')
except:
return code.reply('{red}No quotes to delete.')
lines = fn.readlines()
fn.close()
try:
number = int(text)
except:
code.reply('Please enter the quote number you would like to delete.')
return
newlines = lines[:number - 1] + lines[number:]
fn = open('quotes.txt', 'w')
for line in newlines:
txt = uc.encode(line)
if txt:
fn.write(txt)
if txt[-1] != '\n':
fn.write('\n')
fn.close()
code.reply('{green}Successfully deleted quote {b}%s{b}.' % (number))
开发者ID:CHCMATT,项目名称:Code,代码行数:25,代码来源:quote.py
示例5: collectlines
def collectlines(jenni, input):
"""Creates a temporary storage of most recent lines for s///"""
# don't log things in PM
#channel = (input.sender).encode("utf-8")
channel = uc.decode(input.sender)
channel = uc.encode(channel)
nick = (input.nick).encode("utf-8")
if not channel.startswith('#'): return
search_dict = load_db()
if channel not in search_dict:
search_dict[channel] = dict()
if nick not in search_dict[channel]:
search_dict[channel][nick] = list()
templist = search_dict[channel][nick]
line = input.group()
if line.startswith("s/"):
return
elif line.startswith("\x01ACTION"):
line = line[:-1]
templist.append(line)
else:
templist.append(line)
del templist[:-10]
search_dict[channel][nick] = templist
save_db(search_dict)
开发者ID:jcecil,项目名称:jenni,代码行数:25,代码来源:find.py
示例6: fucking_weather
def fucking_weather(jenni, input):
""".fw (ZIP|City, State) -- provide a ZIP code or a city state pair to hear about the fucking weather"""
## thefuckingweather.com website is not very reliable, in fat this often breaks due to their site
## not returning correct data
text = input.group(2)
if not text:
jenni.reply('INVALID FUCKING INPUT. PLEASE ENTER A FUCKING ZIP CODE, OR A FUCKING CITY-STATE PAIR.')
return
new_text = str()
new_text = uc.encode(text)
search = urllib.quote((new_text).strip())
url = 'http://thefuckingweather.com/?where=%s' % (search)
try:
page = web.get(url)
except:
return jenni.say("I COULDN'T ACCESS THE FUCKING SITE.")
## hacky, yes, I know, but the position of this information has yet to change
re_mark = re.compile('<p class="remark">(.*?)</p>')
re_temp = re.compile('<span class="temperature" tempf="\S+">(\S+)</span>')
re_condition = re.compile('<p class="large specialCondition">(.*?)</p>')
re_flavor = re.compile('<p class="flavor">(.*?)</p>')
re_location = re.compile('<span id="locationDisplaySpan" class="small">(.*?)</span>')
## find relevant information
temps = re_temp.findall(page)
remarks = re_mark.findall(page)
conditions = re_condition.findall(page)
flavor = re_flavor.findall(page)
new_location = re_location.findall(page)
## build return string
response = str()
if new_location and new_location[0]:
response += new_location[0] + ': '
if temps:
tempf = float(temps[0])
tempc = (tempf - 32.0) * (5 / 9.0)
response += u'%.1f°F?! %.1f°C?! ' % (tempf, tempc)
if remarks:
response += remarks[0]
else:
response += "THE FUCKING SITE DOESN'T CONTAIN ANY FUCKING INFORMATION ABOUT THE FUCKING WEATHER FOR THE PROVIDED FUCKING LOCATION. FUCK!"
if conditions:
response += ' ' + conditions[0]
if flavor:
response += ' -- ' + flavor[0].replace(' ', ' ')
jenni.say(response)
开发者ID:NeoMahler,项目名称:jenni,代码行数:60,代码来源:weather.py
示例7: get_results
def get_results(text):
if not text:
return list()
a = re.findall(url_finder, text)
k = len(a)
i = 0
display = list()
passs = False
while i < k:
url = uc.encode(a[i][0])
url = uc.decode(url)
url = uc.iriToUri(url)
url = remove_nonprint(url)
domain = getTLD(url)
if '//' in domain:
domain = domain.split('//')[1]
if not url.startswith(EXCLUSION_CHAR):
passs, page_title = find_title(url)
if bitly_loaded:
bitly = short(url)
bitly = bitly[0][1]
else:
bitly = url
display.append([page_title, url, bitly])
i += 1
return passs, display
开发者ID:jfriedly,项目名称:jenni,代码行数:26,代码来源:url.py
示例8: collectlines
def collectlines(jenni, input):
"""Creates a temporary storage of most recent lines for s///"""
#channel = (input.sender).encode("utf-8")
channel = uc.decode(input.sender)
channel = uc.encode(channel)
nick = (input.nick).encode("utf-8")
search_dict = load_db()
if channel not in search_dict:
search_dict[channel] = dict()
if 'last_said' not in search_dict[channel]:
search_dict[channel]['last_said'] = list()
if nick not in search_dict[channel]:
search_dict[channel][nick] = list()
templist = search_dict[channel][nick]
last_said_templist = search_dict[channel]['last_said']
line = input.group()
try:
line = (line).encode("utf-8")
except Exception:
return
if line.startswith("s/") or line.startswith('!'):
return
elif line.startswith("\x01ACTION"):
line = line[:-1]
templist.append(line)
last_said_templist.append("{}: {}".format(input.nick, line))
del templist[:-50]
del last_said_templist[:-50]
search_dict[channel][nick] = templist
search_dict[channel]['last_said'] = last_said_templist
save_db(search_dict)
开发者ID:nicklewis,项目名称:brittbot,代码行数:31,代码来源:find.py
示例9: delquote
def delquote(jenni, input):
'''.rmquote <number> -- removes a given quote from the database. Can only be done by the owner of the bot.'''
if not input.owner: return
text = input.group(2)
number = int()
try:
fn = open('quotes.txt', 'r')
except:
return jenni.reply('No quotes to delete.')
lines = fn.readlines()
MAX = len(lines)
fn.close()
try:
number = int(text)
except:
jenni.reply('Please enter the quote number you would like to delete.')
return
newlines = lines[:number-1] + lines[number:]
fn = open('quotes.txt', 'w')
for line in newlines:
txt = uc.encode(line)
if txt:
fn.write(txt)
if txt[-1] != '\n':
fn.write('\n')
fn.close()
jenni.reply('Successfully deleted quote %s.' % (number))
开发者ID:BlackRobeRising,项目名称:jenni,代码行数:27,代码来源:quote.py
示例10: addquote
def addquote(code, input):
'''addquote <nick> something they said here -- adds the quote to the quote database.'''
fn = open('quotes.txt', 'a')
output = uc.encode(input.group(2))
fn.write(output)
fn.write('\n')
fn.close()
code.reply('Quote added.')
开发者ID:CHCMATT,项目名称:Code,代码行数:8,代码来源:quote.py
示例11: addquote
def addquote(jenni, input):
'''.addquote <nick> something they said here -- adds the quote to the quote database.'''
text = input.group(2)
fn = open('quotes.txt', 'a')
output = uc.encode(text)
fn.write(output)
fn.write('\n')
fn.close()
jenni.reply('Quote added.')
开发者ID:BlackRobeRising,项目名称:jenni,代码行数:9,代码来源:quote.py
示例12: given_user
def given_user(nick, channel):
nick = uc.encode(nick.lower())
channel = channel.lower()
if channel in self.scores_dict:
if nick in self.scores_dict[channel]:
return self.str_score(nick, channel)
else:
return self.STRINGS["nouser"].format(nick, channel)
else:
return self.STRINGS["nochan"].format(channel)
开发者ID:Jarada,项目名称:jenni,代码行数:10,代码来源:scores.py
示例13: save_db
def save_db(search_dict):
""" save search_dict to find.txt """
search_file = open("find.txt", "w")
for channel in search_dict:
if channel is not "":
for nick in search_dict[channel]:
for line in search_dict[channel][nick]:
channel_utf = uc.encode(channel)
search_file.write(channel_utf)
search_file.write(",")
nick = uc.encode(nick)
search_file.write(nick)
search_file.write(",")
line_utf = line
if not type(str()) == type(line):
line_utf = uc.encode(line)
search_file.write(line_utf)
search_file.write("\n")
search_file.close()
开发者ID:Sandfreak1,项目名称:Code,代码行数:19,代码来源:find.py
示例14: f_lisp
def f_lisp(jenni, input):
'''.lisp <lisp code> -- execute arbitrary lisp code'''
txt = input.group(2)
txt = uc.encode(txt)
try:
output = parse(txt)
output = eval(output)
output = to_string(output)
except Exception, e:
jenni.reply('Scheme Lisp ERROR: %s' % (str(e)))
return
开发者ID:AwwCookies,项目名称:jenni,代码行数:11,代码来源:lispy.py
示例15: addquote
def addquote(phenny, input):
'''.addquote <nick> something they said here -- adds the quote to the quote database.'''
text = input.group(2)
if not text:
return phenny.say('No quote provided')
fn = open('quotes.txt', 'a')
output = uc.encode(text)
fn.write(output)
fn.write('\n')
fn.close()
phenny.reply('Quote added.')
开发者ID:0gobi,项目名称:chinbot,代码行数:11,代码来源:quote.py
示例16: ip_lookup
def ip_lookup(jenni, input):
txt = input.group(2)
if not txt:
return jenni.reply("No search term!")
txt = uc.encode(txt)
query = uc.decode(txt)
response = "[IP/Host Lookup] "
try:
page = web.get(base + txt)
except IOError, err:
return jenni.say('Could not access given address. (Detailed error: %s)' % (err))
开发者ID:myano,项目名称:jenni,代码行数:11,代码来源:ip.py
示例17: quote
def quote(s, safe='/'): # quote('abc def') -> 'abc%20def'
s = uc.encode(s)
s = uc.decode(s)
safe += always_safe
safe_map = dict()
for i in range(256):
c = chr(i)
safe_map[c] = (c in safe) and c or ('%%%02X' % i)
try:
res = map(safe_map.__getitem__, s)
except:
return ''
return ''.join(res)
开发者ID:AwwCookies,项目名称:jenni,代码行数:13,代码来源:cleverbot.py
示例18: get_results
def get_results(text, manual=False):
if not text:
return False, list()
a = re.findall(url_finder, text)
k = len(a)
i = 0
display = list()
passs = False
channel = str()
if hasattr(text, 'sender'):
channel = text.sender
while i < k:
url = uc.encode(a[i][0])
url = uc.decode(url)
url = uc.iriToUri(url)
url = remove_nonprint(url)
domain = getTLD(url)
if '//' in domain:
domain = domain.split('//')[1]
if 'i.imgur.com' in url and url.startswith('http://'):
url = url.replace('http:', 'https:')
bitly = url
if not url.startswith(EXCLUSION_CHAR):
passs, page_title = find_title(url)
if not manual:
if bitly_loaded:
if channel and channel not in simple_channels:
bitly = short(url)
if bitly:
bitly = bitly[0][1]
display.append([page_title, url, bitly, passs])
else:
## has exclusion character
if manual:
## only process excluded URLs if .title is used
url = url[1:]
passs, page_title = find_title(url)
display.append([page_title, url, bitly, passs])
i += 1
## check to make sure at least 1 URL worked correctly
overall_pass = False
for x in display:
if x[-1] == True:
overall_pass = True
return overall_pass, display
开发者ID:J3RN,项目名称:jenni,代码行数:49,代码来源:url.py
示例19: e
def e(m):
entity = m.group()
if entity.startswith("&#x"):
cp = int(entity[3:-1], 16)
meep = unichr(cp)
elif entity.startswith("&#"):
cp = int(entity[2:-1])
meep = unichr(cp)
else:
char = name2codepoint[entity[1:-1]]
meep = unichr(char)
try:
return uc.decode(meep)
except:
return uc.decode(uc.encode(meep))
开发者ID:valeness,项目名称:bl4ckb0t,代码行数:15,代码来源:twitter.py
示例20: addinsult
def addinsult(jenni, input):
""".iadd <insult> -- adds a harsh adjetive to the insult database"""
try:
insultFilename = os.path.expanduser('~/.jenni/insult.'+ jenni.config.insult_lang +'.txt')
except:
jenni.say("You need to configure the default language!")
return
text = input.group(2)
text = uc.encode(text)
fn = open(insultFilename, "a")
fn.write(text)
fn.write("\n")
fn.close()
jenni.reply("Insult added.")
开发者ID:AwwCookies,项目名称:jenni,代码行数:15,代码来源:insult.py
注:本文中的modules.unicode.encode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论