hbbs

[archived] bbs.hlirc.net
git clone https://hhvn.uk/hbbs
git clone git://hhvn.uk/hbbs
Log | Files | Refs | README | LICENSE

atom.sh (1308B)


      1 #!/bin/sh
      2 
      3 cwd=$(dirname $0)
      4 . $cwd/../config.sh
      5 
      6 command -v dateconv >/dev/null || {
      7 	echo "dateconv(1) needed!" >&2
      8 	exit 3
      9 }
     10 
     11 mkdir -p "$hook_atom_output"
     12 
     13 for d in $datadir/boards/*
     14 do
     15 	board=$(basename "$d" | tr '[:lower:]' '[:upper:]')
     16 	awk -F"\t" -v "board=$board" '
     17 	BEGIN {
     18 		printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
     19 		printf "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
     20 		printf "<title type=\"text\">%s</title>\n", board
     21 		printf "<subtitle type=\"text\">Postings from %s</subtitle>\n", board
     22 	}
     23 	{
     24 		gsub(/>/, "\&gt;", $0)
     25 		gsub(/</, "\&lt;", $0)
     26 
     27 		cmd = sprintf("%s %s", "dateconv -i%d-%b-%Y -f%Y-%m-%dT%H:%M:%SZ", $3)
     28 		cmd | getline date
     29 		close(cmd)
     30 
     31 		if ($6 == $7) {
     32 			title = $5
     33 			stitle = title
     34 		} else {
     35 			title = sprintf("Re: %s", stitle)
     36 		}
     37 
     38 		printf "\t<entry>\n"
     39 		printf "\t\t<published>%s</published>\n", date
     40 		printf "\t\t<title type=\"text\">[%s] <%s> %s</title>\n", board, $4, title
     41 		printf "\t\t<author><name>%s</name></author>\n", $4
     42 		printf "\t</entry>\n"
     43 	}
     44 	END {
     45 		printf "</feed>\n"
     46 	}' < "$d/list" | tee "$hook_atom_output/$board.xml"
     47 done | awk '
     48 	BEGIN {
     49 		printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
     50 		printf "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
     51 	}
     52 	/^\t/
     53 	END {
     54 		printf "</feed>\n"
     55 	}' > "$hook_atom_output/all.xml"