From b4a3a6a0051d6759af6daa03f3977a6703e30441 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 20 Feb 2019 23:28:45 +0100 Subject: [PATCH] Added experimental RSS feed parser This is an RSS parser, written in python. It's in development phase so it might not work as expected. Once it does, the aim is to display either events, To-Do's or RSS feeds in the section below the Calendar template. Testers are most welcome. If you find any bugs/improvement ideas, feel free to write me a mail. Thanks in advance --- developers/rss.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 developers/rss.py diff --git a/developers/rss.py b/developers/rss.py new file mode 100644 index 0000000..edf97a5 --- /dev/null +++ b/developers/rss.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +""" +RSS-feed parser for multiple rss-feeds from URLs. +In development for the E-Paper-Calendar software. +Currently in alpha phase. Beta testers more than welcome. Please send me a mail to let me know what can be fixed/improved here. Thanks. + +Copyright by aceisace +""" + +import feedparser +import arrow +import datetime + +rss_feeds=[ + "http://feeds.bbci.co.uk/news/world/rss.xml#", + ] + +"""How old should the oldest posts be in days?""" +max_range = 14 # 2 weeks + + +today = datetime.date.today() +time_span = today - datetime.timedelta(days=max_range) + +for feeds in rss_feeds: + parse = feedparser.parse(feeds) + print(parse['feed']['title']) + print('________________________') + for posts in parse.entries: + # RSS feeds may contain year as '2013' or just '13', hence the 2 options below + try: + post_dt = datetime.datetime.strptime(posts.published, '%a, %d %b %Y %H:%M:%S %Z') + except Exception as e: + post_dt = datetime.datetime.strptime(posts.published, '%a, %d %b %y %H:%M:%S %Z') + + if post_dt.date() >= time_span: + print(arrow.get(post_dt).humanize(), '\n',posts.title) + #local.humanize(locale='ko_kr')