phlog-index - annna - Annna the nice friendly bot.
(HTM) git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
---
phlog-index (3512B)
---
1 #!/bin/sh
2
3 export PATH="$PATH:/home/annna/bin"
4
5 doforce=0
6 if [ $# -gt 0 ];
7 then
8 if [ "$1" = "-f" ];
9 then
10 doforce=1
11 fi
12 fi
13
14 base="$HOME/phlogs"
15 cache="$base/cache"
16 gopherbase="/usr/%s/phlog/%s"
17 ircchans="#bitreich-en #bitreich-de #bitreich-fr #bitreich-nl #bitreich-con #bitreich-it irc.libera.chat/#gopherproject #bitreich-zh"
18
19 find /home/*/gopher/phlog \
20 -name "*.md" \
21 -printf "%f %T@ %u %p\n" > $cache/lsr.new
22
23 cd $cache
24
25 if [ -e lsr.old ] && [ $doforce -eq 0 ];
26 then
27 diff lsr.new lsr.old > lsr.diff
28 else
29 cp lsr.new lsr.diff
30 fi
31
32 if [ $(stat --printf="%s" lsr.diff) -eq 0 ];
33 then
34 exit 0
35 fi
36
37 # First create the links for all news.
38 cat lsr.new \
39 | sort -r \
40 | while read f;
41 do
42 IFS=' ' read -r fname unixt user fpath <<< $f
43 tstamp="$(sed -n 1p "$fpath" | cut -d' ' -f 2)"
44 [ -z "$tstamp" ] && continue
45 title="$(sed -n 3p "$fpath" | sed 's,\t, ,g; s,|,\\|,g';)"
46 [ -z "$title" ] && continue
47
48 gphpth="$(printf "$gopherbase" "$user" "$fname")"
49 printf "[0|%s – »%s« by %s|%s|server|port]\n" \
50 "$tstamp" "$title" "$user" \
51 "$gphpth"
52 done \
53 > ../agg.gph
54
55 # Create the atom feed. Only the first 64 news items.
56 cat lsr.new \
57 | sort -r \
58 | head -n 64 \
59 | while read f;
60 do
61 IFS=' ' read -r fname unixt user fpath <<< $f
62 tstamp="$(sed -n 1p "$fpath" | cut -d' ' -f 2-)"
63 [ -z "$tstamp" ] && continue
64 title="$(sed -n 3p "$fpath" | sed 's,\t, ,g')"
65 [ -z "$title" ] && continue
66
67 updated="$(date -d "${tstamp}" -u +%FT%T%z)"
68 gphpth="$(printf "$gopherbase" "$user" "$fname")"
69 furi="$(printf "gophers://bitreich.org/0%s" "$gphpth")"
70 printf "\t\t<entry>\n"
71 printf "\t\t<id>%s</id>\n" "$furi"
72 printf "\t\t<title><![CDATA[%s]]></title>\n" "$title"
73 printf "\t\t<link href=\"%s\" />\n" "$furi"
74 printf "\t\t<author><name>%s</name></author>\n" "$user"
75 printf "\t\t<content type=\"text\"><![CDATA["
76 cat $fpath
77 printf "]]></content>\n"
78 printf "\t\t<updated>%s</updated>\n" "$updated"
79 printf "\t\t</entry>\n"
80 done \
81 > ../agg.atom.xml
82
83 # Talk to IRC about the news.
84 if [ $doforce -eq 0 ];
85 then
86 cat lsr.diff \
87 | sort \
88 | while read f;
89 do
90 IFS=' ' read -r dire fname unixt user fpath <<< $f
91 [ -z "$fpath" ] && continue
92 [ -z "$user" ] && continue
93 [ -z "$unixt" ] && continue
94 [ -z "$fname" ] && continue
95 [ -z "$dire" ] && continue
96
97 # If the post disappeared, don't tell IRC.
98 [ "$dire" = ">" ] && continue
99
100 tstamp="$(sed -n 1p "$fpath" | cut -d' ' -f 2)"
101 [ -z "$tstamp" ] && continue
102 title="$(sed -n 3p "$fpath" | sed 's,\t, ,g')"
103 [ -z "$title" ] && continue
104
105 gphpth="$(printf "$gopherbase" "$user" "$fname")"
106
107 for chan in $ircchans;
108 do
109 annna-say -c "$chan" \
110 "$(printf "%s – »%s« by %s gophers://bitreich.org/0%s" \
111 "$tstamp" "$title" "$user" "$gphpth")"
112 # Case against channel flood.
113 sleep 1
114 done
115 # Case against news flood.
116 sleep 2
117 done
118 fi
119
120 cp lsr.new lsr.old
121
122 # Now change the gph files in a really easy way.
123 {
124 printf "/ News Aggregator /+1,/news.gph/-1d\n"
125 printf "/ News Aggregator /r !cat /home/annna/phlogs/agg.gph | head -n 4\n"
126 printf "w\nq\n"
127 } | ed -s /br/gopher/bitreich.gph
128
129 {
130 printf "/ News Aggregator /+1,\$-2d\n"
131 printf "? News Aggregator ?r !cat /home/annna/phlogs/agg.gph\n"
132 printf "w\nq\n"
133 } | ed -s /br/gopher/news.gph
134
135 # Make the atom news file ready for consumption.
136 {
137 printf "/updated/+1,\$-1d\n"
138 printf "?updated?c\n"
139 printf "\t<updated>%s</updated>\n" "$(date -u +%FT%T%z)"
140 printf ".\n"
141 printf "?updated?r !cat /home/annna/phlogs/agg.atom.xml\n"
142 printf "w\nq\n"
143 } | ed -s /br/gopher/news.atom.xml
144