Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
Fletcher Boyd 2013-09-05 10:42:03 +08:00
commit 5a586bb373
4 changed files with 31 additions and 36 deletions

View file

@ -8,16 +8,11 @@ def encode(key, clear):
key_c = key[i % len(key)] key_c = key[i % len(key)]
enc_c = chr((ord(clear[i]) + ord(key_c)) % 256) enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
enc.append(enc_c) enc.append(enc_c)
print "[debug]"
return base64.urlsafe_b64encode("".join(enc)) return base64.urlsafe_b64encode("".join(enc))
def decode(key, enc): def decode(key, enc):
dec = [] dec = []
print " [debug] "
print "key: "+key
print "string: "+enc
enc = base64.urlsafe_b64decode(enc.encode('ascii','ignore')) enc = base64.urlsafe_b64decode(enc.encode('ascii','ignore'))
print "de64: "+enc
for i in range(len(enc)): for i in range(len(enc)):
key_c = key[i % len(key)] key_c = key[i % len(key)]
dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)

View file

@ -1,6 +1,6 @@
# Plugin by Infinity - <https://github.com/infinitylabs/UguuBot> # Plugin by Infinity - <https://github.com/infinitylabs/UguuBot>
from util import hook, http from util import hook, http, text
db_ready = False db_ready = False
@ -42,7 +42,7 @@ def horoscope(inp, db=None, notice=None, nick=None):
title = soup.find_all('h1', {'class': 'h1b'})[1] title = soup.find_all('h1', {'class': 'h1b'})[1]
horoscope = soup.find('div', {'class': 'fontdef1'}) horoscope = soup.find('div', {'class': 'fontdef1'})
result = "\x02%s\x02 %s" % (title, horoscope) result = "\x02%s\x02 %s" % (title, horoscope)
result = http.strip_html(result) result = text.strip_html(result)
#result = unicode(result, "utf8").replace('flight ','') #result = unicode(result, "utf8").replace('flight ','')
if not title: if not title:

View file

@ -11,9 +11,6 @@ from urllib import quote, quote_plus as _quote_plus
from lxml import etree, html from lxml import etree, html
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from HTMLParser import HTMLParser
import htmlentitydefs
# used in plugins that import this # used in plugins that import this
from urllib2 import URLError, HTTPError from urllib2 import URLError, HTTPError
@ -30,26 +27,6 @@ ua_chrome = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.4 (KHTML, ' \
jar = cookielib.CookieJar() jar = cookielib.CookieJar()
class HTMLTextExtractor(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.result = []
def handle_data(self, d):
self.result.append(d)
def handle_charref(self, number):
codepoint = int(number[1:], 16) if number[0] in (u'x', u'X') else int(number)
self.result.append(unichr(codepoint))
def handle_entityref(self, name):
codepoint = htmlentitydefs.name2codepoint[name]
self.result.append(unichr(codepoint))
def get_text(self):
return u''.join(self.result)
def get(*args, **kwargs): def get(*args, **kwargs):
return open(*args, **kwargs).read() return open(*args, **kwargs).read()
@ -133,9 +110,3 @@ def unescape(s):
if not s.strip(): if not s.strip():
return s return s
return html.fromstring(s).text_content() return html.fromstring(s).text_content()
def strip_html(html):
s = HTMLTextExtractor()
s.feed(html)
return s.get_text()

View file

@ -6,6 +6,35 @@
import re import re
from HTMLParser import HTMLParser
import htmlentitydefs
class HTMLTextExtractor(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.result = []
def handle_data(self, d):
self.result.append(d)
def handle_charref(self, number):
codepoint = int(number[1:], 16) if number[0] in (u'x', u'X') else int(number)
self.result.append(unichr(codepoint))
def handle_entityref(self, name):
codepoint = htmlentitydefs.name2codepoint[name]
self.result.append(unichr(codepoint))
def get_text(self):
return u''.join(self.result)
def strip_html(html):
s = HTMLTextExtractor()
s.feed(html)
return s.get_text()
def munge(text, munge_count=0): def munge(text, munge_count=0):
"""munges up text.""" """munges up text."""