first import

This commit is contained in:
Bachir Soussi Chiadmi
2017-06-25 11:55:49 +02:00
commit 14640ec431
2 changed files with 86 additions and 0 deletions
Executable
+49
View File
@@ -0,0 +1,49 @@
#!/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()