Files
python-rss2html/import.py
T
2017-06-25 11:55:49 +02:00

50 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: utf-8 -*-
import feedparser
from bs4 import BeautifulSoup
def main():
# url du flux rss
tpsreac_feed_url = "https://tempsdereaction.wordpress.com/feed/"
# on aspire le flux rss avec feedparser
tpsreac_feeds = feedparser.parse(tpsreac_feed_url)
# base template du fichier html
base = "<html><head></head><body></body></html>"
# create dom for html file base
base_dom = BeautifulSoup(base, 'html.parser')
# page base template
page_base = "<section class='page'></section>"
# boucle sur les entrées racine du flux
for key in tpsreac_feeds:
print(key)
# on boucle sur les entrées du flux rss
for entrie in tpsreac_feeds['entries']:
print('- - - - -',entrie['title'])
# just display entrie keys
for key in entrie:
print(key)
# entries.extend( feed[ "items" ] )
# create page dom
p_dom = BeautifulSoup(page_base, 'html.parser')
# add content in page dom
p_dom.section.append(entrie['summary'])
# add newly created page dom to html dom
base_dom.body.append(p_dom)
# create main html file from filled base html dom
with open("index.html", 'w') as fp:
fp.write(base_dom.prettify(formatter=None))
if __name__ == "__main__":
main()