summaryrefslogtreecommitdiff
path: root/odin/strm/rss_staggered
blob: 2f3bb997545e11568add7e17cc1849b329d25629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!@zsh@/bin/zsh

typeset -A opts
zparseopts -A opts -M -- -delta: d:=-delta -interval: i:=-interval

delta_t=${opts[--delta]:-20}
interval=${opts[--interval]:-3600}

staggerFile=~/.rss-stagger

[[ "${FLOCKER}" != "$0" ]] && exec env FLOCKER="$0" flock -x "${staggerFile}" "$0" "$@" || :

typeset -A feeds
r2e list | while read num junk name junk; do
    num=${num%:}
    feeds[${num}]=${name}
done

max=$(($#feeds))
num=$(((max * delta_t) / interval))
[[ $num -lt 1 ]] && num=1

now=$(cat ${staggerFile} || echo 0)
now=$((now % max))

typeset -a run
run=()

typeset -a names
names=()

n=0

for i in $(seq $((now + 1)) $((now + num + 1))); do
    n=$((i % max))
    run+=$n
    names+=$feeds[${n}]
done

echo $n >! ${staggerFile}

printf "Retrieving: %s\n" ${(j:, :)names}

exec @rss2email@/bin/r2e run $run