-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from VaibhavSys/main
feat: add rss feed
- Loading branch information
Showing
4 changed files
with
1,606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
markdown | ||
feedgen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
Oops, something went wrong.