-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchrss.sh
More file actions
executable file
·32 lines (25 loc) · 873 Bytes
/
Copy pathfetchrss.sh
File metadata and controls
executable file
·32 lines (25 loc) · 873 Bytes
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
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <feeds> <history> <output>
feeds: a text file, listing the RSS feeds to fetch (one link per line)
history: a text file, listing already downloaded files (kept by this program)
output: the directory where downloaded files should be saved"
exit 1
fi
xmlq() {
echo $data | xmllint --xpath $1 -
}
while read url; do
data=$(wget -q -O - "$url")
feed=$(xmlq '//channel/title/text()')
count=$(xmlq 'count(//item)')
echo "$count items in $feed"
for i in $(seq 1 $count); do
title=$(xmlq '//item['$i']/title/text()')
link=$(xmlq '//item['$i']/link/text()')
if ! [ -f "$2" ] || ! grep -q "$link" "$2"; then
echo "Downloading $title ($link) from $feed"
wget -q --content-disposition -P "$3" $link && echo "[$(date)] $title $link" >> "$2"
fi
done
done < "$1"