def recent_feed(): feed = AtomFeed( 'WhibOx Contest 3nd Edition -- CHES 2021 Challenge', feed_url=request.url, url=request.url_root, author="WhibOx organizing committee", subtitle="Submitted challenged order by published date descending") programs = Program.get_all_published_sorted_by_published_time() for program in programs: item_url = f"{request.url_root}candidate/{program._id}.html" title = f'New challenge "{program.funny_name}" submitted' author = program.user.nickname content = render_template('candidate.html', program=program, feed=True) if not author or not author.strip(): author = program.user.username feed.add( id=item_url, title=title, title_type='html', updated=datetime.fromtimestamp(program._timestamp_published), author=author, url=item_url, categories=[{ 'term': program.status }], content=content, content_type='html', ) return feed.get_response()
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 feed(): feed = AtomFeed('BrightonPy Events', feed_url=request.url, url=request.url_root) for meeting in reversed(get_meetings()): # A little hack date = meeting['datetime'] - timedelta(weeks=1) feed.add( meeting['title'], meeting['content'], author=meeting['speaker'], url=urljoin(request.url_root, url_for('meeting', date=meeting['path'])), updated=date, published=date ) return feed.get_response()
def feeds(): feeds = AtomFeed(title="Peach Blog's Feeds", feed_url=request.url, url=request.url_root) posts = Post.query.order_by(Post.create_at.desc()).all() for post in posts: feeds.add(post.title, markdown.html(post.content), content_type='html', author='Leetao', url=get_abs_url(post.title), updated=post.last_update, published=post.last_update) return feeds.get_response()
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()
def feed(blogger): blog_author = Blogger.from_subdomain(blogger) or abort(404) posts = CommitPost.query \ .filter_by(blogger=blog_author) \ .order_by(CommitPost.datetime.desc()) feed = AtomFeed('$ commits-by ' + (blog_author.name or blog_author.username), feed_url=request.url, url=request.url_root) for post in posts: feed.add( post.get_title(), post.get_body(markdown=True), content_type='html', author=blog_author.name or blog_author.username, url=url_for('blog.commit_post', _external=True, blogger=blog_author.username, repo_name=post.repo.full_name, hex=post.hex), updated=post.datetime, published=post.datetime, ) return feed.get_response()
def _parse_feed(self, source_file): try: with io.open(source_file, "r", encoding="utf-8") as f: metadata = json.loads(f.read()) if metadata.get("entries") is None: raise ValueError(_("Missing entries list.")) entries = metadata["entries"] # AtomFeed expects FeedEntry objects for the entries keyword so # remove it from the metadata and add it after the feed is built. del metadata["entries"] feed = AtomFeed(**metadata) [feed.add(self._make_entry(entry)) for entry in entries] except ValueError as error: raise AbortError( _("Invalid feed {source_file}: {error}").format( source_file=source_file, error=str(error))) return feed
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())