Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a simple RSS feed for use in Slack #42

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/render-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ do
done

./venv/bin/python3 ./scripts/render-indices.py
./venv/bin/python3 ./scripts/render-feed.py
./venv/bin/python3 ./scripts/render-feeds.py
45 changes: 0 additions & 45 deletions scripts/render-feed.py

This file was deleted.

81 changes: 81 additions & 0 deletions scripts/render-feeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3

import datetime
from html.parser import HTMLParser
from io import StringIO
from pathlib import Path
import re

from feedgenerator import DefaultFeed
import mistune


def strip_tags(html):
class MLStripper(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.strict = False
self.convert_charrefs= True
RealOrangeOne marked this conversation as resolved.
Show resolved Hide resolved
self.text = StringIO()

def handle_data(self, d):
self.text.write(d)

def get_data(self):
return self.text.getvalue()

s = MLStripper()
s.feed(html)
return s.get_data()

FEED_ARGS = {
"title": "SR(A)WN",
"link": "https://studentrobotics.org/srawn/",
"description": "Student Robotics (Almost) Weekly Newsletter",
"author_name": "Student Robotics"
}


working_dir = Path('.')
feed = DefaultFeed(**FEED_ARGS)
simple_feed = DefaultFeed(**FEED_ARGS)
md = mistune.create_markdown()


for md_path in sorted(working_dir.glob("SR20*/*.md")):
filename_match = re.match("^(20\d{2}-\d{2}-\d{2})-srawn-(\d{2})$", md_path.stem)
if not filename_match:
exit(f"{md_path.stem} does not match format. Run the linter.")
date, issue = filename_match.groups()

folder_match = re.match("^(SR20\d{2})$", md_path.parent.name)
if not folder_match:
exit(f"{md_path.parent.name} does not match format. Run the linter.")
sryear, = folder_match.groups()

link = f"https://studentrobotics.org/srawn/{md_path.parent.stem}/{md_path.stem}.html"
content = md(md_path.read_text())
title = f"{sryear} Issue {issue}"
publish_date = datetime.date.fromisoformat(date)

feed.add_item(
title=title,
link=link,
unique_id=link,
pubdate=publish_date,
description=content,
)
simple_feed.add_item(
title=title,
link=link,
unique_id=link,
pubdate=publish_date,
description=strip_tags(content),
)

with (working_dir / "out" / "html" / "rss.xml").open("w") as f:
feed.write(f, "utf-8")

with (working_dir / "out" / "html" / "rss-simple.xml").open("w") as f:
RealOrangeOne marked this conversation as resolved.
Show resolved Hide resolved
simple_feed.write(f, "utf-8")