atom.py 1004 B

1234567891011121314151617181920212223242526272829303132
  1. from typing import List
  2. from urllib.parse import urljoin
  3. from blog import Post
  4. from feedgen.feed import FeedGenerator
  5. def get_abs_url(url, request):
  6. """ Returns absolute url by joining post url with base url """
  7. return urljoin(request.url_root, url)
  8. def make_feed(posts: List[Post]) -> None:
  9. fg = FeedGenerator()
  10. fg.id('http://lernfunk.de/media/654321')
  11. fg.title('Some Testfeed')
  12. fg.author({'name': 'John Doe', 'email': 'john@example.de'})
  13. fg.link(href='http://example.com', rel='alternate')
  14. fg.logo('http://ex.com/logo.jpg')
  15. fg.subtitle('This is a cool feed!')
  16. fg.link(href='http://larskiesow.de/test.atom', rel='self')
  17. fg.language('en')
  18. fg.contributor(name='John Doe', email='jdoe@example.com')
  19. # posts.reverse()
  20. for p in posts[15::-1]:
  21. fe = fg.add_entry()
  22. fe.id(str(p.id))
  23. fe.title(p.title)
  24. fe.content(p.body)
  25. fe.link(href=f"http://127.0.0.1:5000/post/{p.id}")
  26. fg.atom_file('templates/atom.xml')