-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbmarker
executable file
·64 lines (54 loc) · 1.39 KB
/
nbmarker
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
MARKDIR=/var/newsbeuter/marks
TITLE="shared items"
LINK="http://domain.com/index.php/read"
SELF="http://domain.com/nb.rss"
OUTFILE=/var/www/nb.rss
DESCRIPTION="stuff on the web I thought was cool"
LANGUAGE="en"
COPYRIGHT="Public Domain"
TIMETOLIVE="1440" #that's in seconds
MAXITEMS="25"
function writeitem {
TITLE=$(echo ${2} | sed 's/\&/\&\;/g')
LINK=$(echo ${1} | sed 's/\&/\&\;/g')
NOW=$(date +%s)
cat <<EOITEM > ${MARKDIR}/mark.${NOW}
<item>
<title>${TITLE}</title>
<pubDate>$(date +"%a, %d %b %Y %T %Z")</pubDate>
<guid>${SELF}/${NOW}</guid>
<link>${LINK}</link>
</item>
EOITEM
}
function cleanup {
ls -r1 ${MARKDIR}/mark* | tail -n +$((${MAXITEMS}+1)) | xargs rm -f
}
function writefeed {
cat <<EOHEAD
<?xml version="1.0" encoding="utf-8"?>
<!-- generator="newsbeuter2rss/0.2" -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>${TITLE}</title>
<link>${LINK}</link>
<description>${DESCRIPTION}</description>
<atom:link href="${SELF}" rel="self" type="application/rss+xml" />
<language>${LANGUAGE}</language>
<copyright>${COPYRIGHT}</copyright>
<ttl>${TIMETOLIVE}</ttl>
EOHEAD
cat $(ls -r ${MARKDIR}/mark*)
cat << EOFOOT
</channel>
</rss>
EOFOOT
}
if [ $# -ge 2 ]
then
writeitem "${1}" "${2}"
cleanup
fi
writefeed > ${OUTFILE}
tidy -qe -xml ${OUTFILE}