Multifeeding RSS streams into points of access. https://multi.vvvvvvaria.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
2.1 KiB

import feedparser
from simpledatabase import SimpleDatabase
import json
from datetime import date, timedelta
def load():
""" Load all feeds """
feeds = open('feeds.txt').readlines()
db = SimpleDatabase('feeds.json', 'feeds.log')
tmp = {}
for x, feed in enumerate(feeds):
parsed = feedparser.parse(feed)
x = str(x)
tmp[x] = {}
tmp[x]['title'] = parsed.feed.title
tmp[x]['link'] = parsed.feed.link
tmp[x]['description'] = parsed.feed.description
tmp[x]['entries'] = parsed.entries
db.update(tmp)
return db
def latest(num):
""" Placeholder request """
request = [
{
"feedtitle" : "Varia EN",
"post": "hello world",
"date" : "Monday 15th of February 2021",
"url" : "https://vvvvvvaria.org/en/rr-wireless-imagination-1.html"
}
]
return request
def today():
""" Collect posts from today """
db = load()
today = str(date.today()).split('-')
today_year = "{:02d}".format(int(today[0]))
today_month = "{:02d}".format(int(today[1]))
today_day = "{:02d}".format(int(today[2]))
print('TODAY =', today_year, today_month, today_day)
request = []
for x, feed in db.items():
for post in feed['entries']:
if post['published_parsed']:
year = "{:02d}".format(post['published_parsed'][0])
month = "{:02d}".format(post['published_parsed'][1])
day = "{:02d}".format(post['published_parsed'][2] + 1)
print('POST DATE =', year, month, day)
# Check if this post is published today
if year == today_year:
if month == today_month:
if day == today_day:
request.append(post)
return request
def past(days):
""" Collect posts from this week """
db = load()
point_in_the_past = date.today() - timedelta(int(days))
print(f"{ days } days in the past =", point_in_the_past)
request = []
for x, feed in db.items():
for post in feed['entries']:
if post['published_parsed']:
year = post['published_parsed'][0]
month = post['published_parsed'][1]
day = post['published_parsed'][2]
post_date = date(year, month, day)
print("post date =",post_date)
if post_date > point_in_the_past:
request.append(post)
return request