def test_add_to_feed(self): test_tags = ["a new tag", "a new new tag"] tag_keys = self.tags.add(test_tags) category_key = self.categories.add("category") self.posts.add("a title", "body text", category_key, tag_keys) feed_org = AtomFeed('Recent Articles', feed_url='http://localhost/recent.atom', url="") feed_model = AtomFeed('Recent Articles', feed_url='http://localhost/recent.atom', url="") for post in self.posts: catname = post.get_category() url = "/".join([ catname, post.timestamp.strftime('%B'), post.timestamp.strftime('%Y') ]) feed_org.add(post.title, post.body, content_type='html', author='Armen Arsakian', url=make_external("http://localhost/recent.atom", url), updated=post.updated, published=post.timestamp) feed = self.posts.add_to_feed(feed_model, "http://localhost/recent.atom") self.assertEqual(feed_org.to_string(), feed.to_string())
def test_feed(self): category_key = self.categories.add("category") existing_tags = ["a new tag", "a new new tag"] existing_tag_keys = self.tags.add(existing_tags) self.posts.add("about", "body text", category_key, existing_tag_keys) response = self.client.get(path='/recent.atom') feed = AtomFeed('Recent Articles', feed_url='http://localhost/recent.atom', url=request.url_root) feed = self.posts.add_to_feed(feed, request.url) return self.assertEqual(feed.to_string(), response.data.decode('utf8'))
class FeedBuilder(BlogBuilder): """Transform blog metadata and posts into an Atom feed.""" def __init__(self, metadata): self.metadata = metadata self._feed = AtomFeed(**metadata) def add(self, posts): """Add blog posts to the feed.""" for post in posts: self._feed.add( FeedEntry( summary=post.summary, title=post.title, title_type="html", url=post.url, updated=post.date, )) def _generate_output(self): return self._feed.to_string()
from ciso8601 import parse_rfc3339 from jnrbase.attrdict import AttrDict from lxml import html from feedwerk.atom import AtomFeed with open(sys.argv[1]) as f: page = html.parse(f) with open('data/µnotes.json') as f: notes = json.load(f, object_hook=AttrDict) with open('data/config.json') as f: config = json.load(f, object_hook=AttrDict) feed = AtomFeed(**config) for note, post in list(zip(reversed(notes), page.getroot().cssselect('.note')))[:15]: title = note.text content = html.tostring(post, True).decode() content = content.strip().replace('\n', '') time = parse_rfc3339(post.cssselect('p.meta time')[0].get('datetime')) feed.add(title=title, content=content, content_type='html', url='%s#%s' % (config.url, post.get("id")), updated=time, published=time, xml_base=config.url) print(feed.to_string())