pub / linkagg

OPML sources for the left news aggregator
git clone src.jayvii.de/pub/linkagg.git
Home | Log | Files | Exports | Refs | README | RSS

commit c57133401dc4cfd4b5eeb5bfedcd0dec76497c4e
parent 822d58f36aef387dfed8975226071c2fcf6c86d1
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Fri, 11 Apr 2025 22:54:26 +0200

feat: uniformly using English; introducing optarg

Diffstat:
MMakefile | 5++++-
Mgen_opml.sh | 88++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
2 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,8 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-FileCopyrightText: 2025 JayVii <jayvii[AT]posteo[DOT]de> + gen_opml: mkdir -p ./opml # ensure directory exists rm -r ./opml mkdir -p ./opml - ./gen_opml.sh + ./gen_opml.sh -s quellen.tsv diff --git a/gen_opml.sh b/gen_opml.sh @@ -1,9 +1,33 @@ #!/usr/bin/env bash +# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-FileCopyrightText: 2025 JayVii <jayvii[AT]posteo[DOT]de> + +# Gather input ----------------------------------------------------------------- + +# fetch source file from the "-s " flag +while getopts "s:" opt; do + case $opt in + s) + export sources_file="$OPTARG" + ;; + esac +done + +# exit if sourcefile is not provided +if [ -z $sources_file ]; then + echo "Usage: $0 -s /path/to/sources.tsv" > /dev/stderr + exit 1 +fi + # Functions -------------------------------------------------------------------- function parse_tsv_line { + + # escape input as replacement string for regex local repl="\\${2}" + + # split up single-line string into its four parts and return according part echo "$1" | \ tail -n 1 | \ sed -E -e "s/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)$/${repl}/" @@ -11,25 +35,30 @@ function parse_tsv_line { # Script ----------------------------------------------------------------------- +# User output +echo "Gather information from ${sources_file} ..." + # parse TSV file and assign to arrays while read -r line; do name_tmp=$(parse_tsv_line "$line" 1) - katg_tmp=$(parse_tsv_line "$line" 2) + catg_tmp=$(parse_tsv_line "$line" 2) addr_tmp=$(parse_tsv_line "$line" 3) rssa_tmp=$(parse_tsv_line "$line" 4) name+=("$name_tmp") - katg+=("$katg_tmp") + catg+=("$catg_tmp") addr+=("$addr_tmp") rssa+=("$rssa_tmp") -done < quellen.tsv +done < ${sources_file} # create an array of unique categories -for i in $(seq 1 1 ${#katg[@]}); do - katg_liste+="$(echo ${katg[$i]} | sed -e 's/\s/_/g' -e 's/,/\ /g') " +## create space separated single string of categories +for i in $(seq 1 1 ${#catg[@]}); do + catg_list+="$(echo ${catg[$i]} | sed -e 's/\s/_/g' -e 's/,/\ /g') " done -katg_liste=($(echo "$katg_liste" | tr ' ' '\n' | sort -u | tr '\n' ' ')) +## sort and return only unique categories into array +catg_list=($(echo "$catg_list" | tr ' ' '\n' | sort -u | tr '\n' ' ')) # define OPML header opml_header="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" @@ -39,25 +68,28 @@ opml_header+=" <title>LinkAgg Newsaggregator</title>\n" opml_header+=" <dateCreated>$(LC_ALL=en date)</dateCreated>\n" opml_header+=" </head>\n" -# build OPML file kategory by kategory -for k in ${katg_liste[@]}; do +# build OPML file category-by-category +for cat in ${catg_list[@]}; do - k=$(echo "$k" | tr '_' ' ') - echo "Bearbeite: ${k}..." + # re-introduce spaces into categories again + cat=$(echo "$cat" | tr '_' ' ') - # Start der Kategorien "outline" - opml_body=" <outline title=\"$k\" text=\"$k\">\n" + # output for user + echo "Generating ./opml/${cat}.opml" - # Schleife durch alle Quellen + # First part of opml body definition (category outline) + opml_body=" <outline title=\"$cat\" text=\"$cat\">\n" + + # Loop through each source individually for i in $(seq 1 1 ${#name[@]}); do - # Test ob Kategorie in Quelle enthalten ist - if [ $(echo ${katg[$i]} | grep -c -E "(^|,)${k}($|,)") -gt 0 ]; then + # If source contains the category, add it to the OPML body + if [ $(echo ${catg[$i]} | grep -c -E "(^|,)${cat}($|,)") -gt 0 ]; then - # RSS-Eintrag für zutreffende Quelle + # generate OPML line for the current source a="title=\"${name[$i]}\"" b="text=\"${name[$i]}\"" - c="category=\"$(echo ${katg[$i]} | sed -E -e 's/(^|,)/\1\//g')\"" + c="category=\"$(echo ${catg[$i]} | sed -E -e 's/(^|,)/\1\//g')\"" d="htmlUrl=\"${addr[$i]}\"" e="xmlUrl=\"${rssa[$i]}\"" opml_body+=" <outline $a $b $c $d $e type=\"rss\" />\n" @@ -66,24 +98,24 @@ for k in ${katg_liste[@]}; do done - # Ende der Kategorie "outline" + # Last part of opml body definition opml_body+=" </outline>\n" - # Übernahme in globalen OPML-Körper + # Copy current category opml body to the global string variable opml_body_global+="$opml_body" - # Export der kategorien OPML-Datei - kat_header=$( + # export current category into its own category file + cat_header=$( echo "$opml_header" | sed -E -e "s/(<\/title>)/Kategorie: ${k}\1/" ) - kat_opml="${kat_header} <body>\n${opml_body} </body>\n</opml>" - printf "${kat_opml}\n" | tee "./opml/${k}.opml" > /dev/null + cat_opml="${cat_header} <body>\n${opml_body} </body>\n</opml>" + printf "${cat_opml}\n" | tee "./opml/${cat}.opml" > /dev/null done -# Export der globalen OPML-Datei -opml_head=" <head>\n" -opml_head+=" <title>LinkAgg Newsaggregator</title>\n" -opml_head+=" </head>\n" +# Export of global OPML file +echo "Generating ./opml/linkagg.opml" opml="${opml_header}${opml_head} <body>\n${opml_body_global} </body>\n</opml>" -printf "${opml}\n" | tee "./opml/linkagg.opml.xml" > /dev/null +printf "${opml}\n" | tee "./opml/linkagg.opml" > /dev/null + +echo "Done!"