Hopefully fixed encoding issues

with the dirtiest trick out there...
master
pictuga 2013-02-27 15:12:32 +01:00
parent 0eaa1b3ab9
commit e305f387ab
1 changed files with 10 additions and 5 deletions

15
morss
View File

@ -11,10 +11,17 @@ def log(txt):
if os.getenv('DEBUG', False): if os.getenv('DEBUG', False):
print txt print txt
def xmlclean(xml):
xml = list(xml)
for pos in range(0,len(xml)):
if ord(xml[pos]) < 32:
xml[pos] = None
return ''.join([c for c in xml if c])
node = sys.argv[1] if len(sys.argv) > 1 else "//h1/.." node = sys.argv[1] if len(sys.argv) > 1 else "//h1/.."
xml = sys.stdin.read() xml = xmlclean(sys.stdin.read())
rss = etree.fromstring(xml) rss = etree.XML(xml)
items = rss.xpath('//item') items = rss.xpath('//item')
cache = expanduser("~") + "/.cache/morss" cache = expanduser("~") + "/.cache/morss"
@ -22,11 +29,9 @@ if not os.path.exists(cache):
os.makedirs(cache) os.makedirs(cache)
for item in items: for item in items:
title = item.findtext('title') link = item.findtext('link').encode('utf-8')
link = item.findtext('link')
desc = item.xpath('description')[0] desc = item.xpath('description')[0]
log(title)
log(link) log(link)
cached = cache + "/" + str(hash(link)) cached = cache + "/" + str(hash(link))