Skip to content

Commit

Permalink
Merge pull request #47 from VaibhavSys/main
Browse files Browse the repository at this point in the history
feat: add rss feed
  • Loading branch information
wdhdev authored Jan 16, 2024
2 parents 4ac4dab + 87fb076 commit 8b0162c
Show file tree
Hide file tree
Showing 4 changed files with 1,606 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/rss.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: RSS Feed

on:
push:
branches: [main]
paths:
- "data/*"

workflow_dispatch: {}

permissions:
contents: write

jobs:
generate:
name: Generate
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
cache-dependency-path: rss-requirements.txt

- name: Install Dependencies
run: pip install -r rss-requirements.txt

- name: Update RSS Feed
run: python scripts/rss.py

- name: Commit
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add website/rss.xml
git commit -m "chore: update rss feed"
git push
2 changes: 2 additions & 0 deletions rss-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
markdown
feedgen
60 changes: 60 additions & 0 deletions scripts/rss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import time
import markdown
from feedgen.feed import FeedGenerator

DATA_DIR = "data"
RSS_PATH = "website/rss.xml"
START_ENTRY = "_start.md"
END_ENTRY = "_end.md"


def add_entry(feed: FeedGenerator, filename: str):
print(f"Adding entry for file: {filename}")

start_time = time.time()

with open(f"{DATA_DIR}/{filename}", "r") as f:
md_content = f.read()
html_content = markdown.markdown(md_content, extensions=["markdown.extensions.tables"])
fe = feed.add_entry()
formatted_filename = filename.lower()[:-3].replace("_", "-")
fe.title(formatted_filename)
fe.link(href=f"https://free-for.life/#/?id={formatted_filename}")
fe.description(html_content)

end_time = time.time()
print(f"Added entry for file: {filename} in {end_time - start_time} seconds.")


def main():
start_time = time.time()
fg = FeedGenerator()
fg.title("Free For Life")
fg.link(href="https://free-for.life/", rel="alternate")
fg.description("A massive list including a huge amount of products and services that are completely free!")
fg.language("en")

print("Starting to generate RSS feed...")
add_entry(fg, END_ENTRY)

for filename in os.listdir(DATA_DIR):
if not filename.endswith(".md"):
continue
if filename in [START_ENTRY, END_ENTRY]:
continue
add_entry(fg, filename)

add_entry(fg, START_ENTRY)

fg.rss_file(RSS_PATH)

end_time = time.time()

print(f"RSS feed generated and saved to: {RSS_PATH} in {end_time - start_time} seconds.")


if __name__ == "__main__":
print("Starting script...")
main()
print("Script finished.")
Loading

0 comments on commit 8b0162c

Please sign in to comment.