diff --git a/.github/workflows/update-rss.yml b/.github/workflows/update-rss.yml new file mode 100644 index 0000000..ba30c19 --- /dev/null +++ b/.github/workflows/update-rss.yml @@ -0,0 +1,28 @@ +name: Update RSS Feed + +on: + push: + branches: + - master + +jobs: + update-rss: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.11 + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run update + run: python update.py + env: + MINIFLUX_ENDPOINT: ${{ secrets.MINIFLUX_ENDPOINT }} + MINIFLUX_API_KEY: ${{ secrets.MINIFLUX_API_KEY }} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6a09e8d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +miniflux==1.0.1 +mistune==3.0.2 +Requests==2.31.0 diff --git a/update.py b/update.py new file mode 100644 index 0000000..cef6607 --- /dev/null +++ b/update.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import miniflux +import mistune +import os +import pprint +import requests + +from mistune.plugins.table import table + + +markdown = mistune.create_markdown(renderer='ast', plugins=[table]) + + +def format_rss(blogroll_url): + table_line = [] + rss_urls = [] + checked_rss_urls = [] + + r = requests.get(blogroll_url) + ast = markdown(r.text) + + for elem in ast: + if isinstance(elem, dict) and elem['type'] == 'table': + for tbl_elem in elem['children']: + if tbl_elem['type'] == "table_body": + for line_elem in tbl_elem['children']: + table_line.append(line_elem['children'][2]) + for elem in table_line: + raw_data: str = elem['children'][0]['raw'] + if raw_data.startswith("http"): + rss_urls.append(raw_data) + + for url in rss_urls: + print("getting {}".format(url)) + try: + req = requests.get(url) + if req.status_code != 200: + print(f"{url} with status code {req.status_code}") + continue + if req.text.startswith("