summaryrefslogtreecommitdiffhomepage
path: root/www/scripts
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-12-12 17:07:16 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-12-12 17:07:16 +0800
commit51265f08cb9b19ebb01375d05057fdbc338b6355 (patch)
tree8f02e0c2cab0e0772655133cd67d221594753936 /www/scripts
parent015923746c4d3db65cb7eef3327b34532a7c1ae9 (diff)
add build for rss feeds
Diffstat (limited to 'www/scripts')
-rwxr-xr-xwww/scripts/update-feeds.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/www/scripts/update-feeds.sh b/www/scripts/update-feeds.sh
new file mode 100755
index 0000000..8dff837
--- /dev/null
+++ b/www/scripts/update-feeds.sh
@@ -0,0 +1,28 @@
1#! /bin/bash
2
3cd /srv/rss
4mkdir -p feeds
5
6LIST=${LIST:?}
7curlOpts='--insecure'
8
9cat "${LIST}" | while read url interval tags; do
10 feed=feeds/${url//\//%2F}
11 unset next_fetch; declare -i next_fetch=0
12
13 # Get time of next fetch
14 if [ -f $feed ]; then
15 interval=$(<<<"$interval" sed 's/m/minute/; s/h/hour/; s/d/day/;')
16 next_fetch=$(date -d "$(date -r $feed) + $interval" +'%s')
17 fi
18
19 # Do not fetch feed if interval covers current time
20 [ $(date +'%s') -lt $next_fetch ] && continue
21
22 # Set limit of HTTP connections
23 while [ $(jobs -p | wc -l) -ge 10 ]; do
24 sleep 0.5;
25 done
26
27 curl -s $curlOpts $url -o $feed || echo Fail to fetch $url >&2 &
28done