Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Mar 4, 2016
1 parent 51ffeb6 commit 6177df7
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions feedpipe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/python

import feedparser
import xe
import feed.atom as FA
import feed.date.tools as FT
from uuid import uuid4
from datetime import datetime

Expand Down Expand Up @@ -116,15 +118,31 @@ def cat(self, feeds):
if 'author' in e:
entry.author = FA.Author(e.author)

if 'content' in e:
entry.content = e.content[0].value
class Div(xe.NestElement):
def __init__(self, content='', **attrs):
xe.NestElement.__init__(self, tag_name="div")
for k, v in attrs.items():
self.attrs[k] = v
self.content = xe.XMLText(content)

class Content(xe.NestElement):
def __init__(self, content='', _type='xhtml'):
xe.NestElement.__init__(self, tag_name="content")
self.attrs["type"] = _type
self.div = Div(xmlns="http://www.w3.org/1999/xhtml")
self.div.content = content

if 'summary' in e:
entry._lock = False
entry.content = Content(e.summary)
entry._lock = True
elif 'content' in e:
entry.content = Content(e.content[0].value)

if 'link' in e:
link = FA.Link(e.link)
entry.link = link

if 'summary' in e:
entry.summary = e.summary

if 'tags' in e:
entry.categories = FA.Collection(
Expand All @@ -134,12 +152,7 @@ def cat(self, feeds):
for tag in e.tags)

if 'published' in e:
try:
entry.published = e.published
except ValueError:
entry.published = datetime.strptime(
e.published, '%a, %d %b %Y %H:%M:%S %Z'
).isoformat()
entry.published = FT.tf_from_s(e.published)

self.entries.append(entry)

Expand Down Expand Up @@ -296,7 +309,7 @@ def as_xml(self):
xmldoc = FA.XMLDoc()
xmldoc.root_element = self.as_atom_obj()

return str(xmldoc)
return unicode(xmldoc).encode('utf-8').strip()

def count(self):
"""
Expand Down

0 comments on commit 6177df7

Please sign in to comment.