-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss.py
60 lines (48 loc) · 1.79 KB
/
rss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import configparser
from pathlib import Path
from datetime import datetime
import pytz
# For the RSS feed generation
# https://feedgen.kiesow.be/
from feedgen.feed import FeedGenerator
def main():
config = configparser.ConfigParser()
config.read("config.ini")
fg = FeedGenerator()
fg.id("https://codecurrents.blog")
fg.title("Code & Currents")
fg.author({"name": "Michel Lavoie", "email": "[email protected]"})
fg.link(href="https://codecurrents.blog", rel="alternate")
fg.subtitle("Michel Lavoie's blog")
fg.link(href="https://codecurrents.blog/feed", rel="self")
fg.language("en")
briefs = Path(config["Path"]["briefs"]).glob("*.md")
for brief in sorted(briefs):
pub_date = brief.stem
with open(brief, "r") as file:
for line in file:
if line[:2] == "# ":
title = line[2:-1]
break
with open(brief, "r") as file:
for line in file:
if line[0] == "*" and line[-2] == "*":
description = line[1:-2]
break
id = f"{config['Site']['url']}/article/{pub_date}"
fe = fg.add_entry()
fe.id(id)
fe.title(title)
fe.link(href=id)
fe.description(description)
fe.author({"name": config["Site"]["author"], "email": config["Site"]["email"]})
fe.content(
f'{description}<br /><br />See full article at: <a href="{id}">{id}</a>'
)
date = datetime.strptime(pub_date, "%Y-%m-%d")
timezone = pytz.timezone(config["Site"]["timezone"])
date_with_timezone = timezone.localize(date)
fe.pubDate(date_with_timezone)
fg.rss_file(f"{config['Path']['static']}/rss.xml", pretty=True)
if __name__ == "__main__":
main()