import.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import feedparser
  4. from bs4 import BeautifulSoup
  5. def main():
  6. # url du flux rss
  7. tpsreac_feed_url = "https://tempsdereaction.wordpress.com/feed/"
  8. # on aspire le flux rss avec feedparser
  9. tpsreac_feeds = feedparser.parse(tpsreac_feed_url)
  10. # base template du fichier html
  11. base = "<html><head></head><body></body></html>"
  12. # create dom for html file base
  13. base_dom = BeautifulSoup(base, 'html.parser')
  14. # page base template
  15. page_base = "<section class='page'></section>"
  16. # boucle sur les entrées racine du flux
  17. for key in tpsreac_feeds:
  18. print(key)
  19. # on boucle sur les entrées du flux rss
  20. for entrie in tpsreac_feeds['entries']:
  21. print('- - - - -',entrie['title'])
  22. # just display entrie keys
  23. for key in entrie:
  24. print(key)
  25. # entries.extend( feed[ "items" ] )
  26. # create page dom
  27. p_dom = BeautifulSoup(page_base, 'html.parser')
  28. # add content in page dom
  29. p_dom.section.append(entrie['summary'])
  30. # add newly created page dom to html dom
  31. base_dom.body.append(p_dom)
  32. # create main html file from filled base html dom
  33. with open("index.html", 'w') as fp:
  34. fp.write(base_dom.prettify(formatter=None))
  35. if __name__ == "__main__":
  36. main()