diff --git a/Hooks/scripts.d/generate-rss-snippet b/Hooks/scripts.d/generate-rss-snippet new file mode 100755 index 0000000..960aa31 --- /dev/null +++ b/Hooks/scripts.d/generate-rss-snippet @@ -0,0 +1,12 @@ +#!/bin/bash + +firstRSSEntryPy=$(dirname "$0")/../../Python/first_rss_entry.py +if [ -d /var/lib/gitea/custom/public/assets/ ] && [ -d ./rss/ ]; then + sudo mkdir -p /var/lib/gitea/custom/public/assets/rss-snippets + for feed in `find ./rss/ -type f -name '*.xml'`; do + feedshort="$(basename "$feed" | sed 's/.xml$//')" + python3 "$firstRSSEntryPy" "$feed" > /tmp/${feedshort} + sudo mv /tmp/${feedshort} /var/lib/gitea/custom/public/assets/rss-snippets + done + sudo chown -R gitea: /var/lib/gitea/custom/public/assets/rss-snippets +fi diff --git a/Python/first_rss_entry.py b/Python/first_rss_entry.py new file mode 100644 index 0000000..0db1a9a --- /dev/null +++ b/Python/first_rss_entry.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import sys +import xml.etree.ElementTree as ET + +try: + tree = ET.parse(sys.argv[1]) + firstentry = tree.find('{http://www.w3.org/2005/Atom}entry') + appliedarr = {} + for child in firstentry: + shortattr = child.tag.replace('{http://www.w3.org/2005/Atom}','') + appliedarr.update({shortattr : child.text}) + print('
'+appliedarr['summary']
+ + '
Updated: ' + appliedarr['updated'] + ' '
+ +' Read More
'+appliedarr['summary'] + + ' Updated: ' + appliedarr['updated'] + +' Read More