-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrss_parser.sh
More file actions
42 lines (40 loc) · 919 Bytes
/
Copy pathrss_parser.sh
File metadata and controls
42 lines (40 loc) · 919 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
33
34
35
36
37
38
39
40
41
#!/bin/sh
xmlgetnext () {
local IFS='>'
read -d '<' TAG VALUE
}
cat $1 | while xmlgetnext ; do
case $TAG in
'item')
title=''
link=''
pubDate=''
description=''
;;
'title')
title="$VALUE"
;;
'link')
link="$VALUE"
;;
'pubDate')
# convert pubDate format for <time datetime="">
datetime=$( date --date "$VALUE" --iso-8601=minutes )
pubDate=$( date --date "$VALUE" '+%D %H:%M%P' )
;;
'description')
# convert '<' and '>' to '<' and '>'
description=$( echo "$VALUE" | sed -e 's/</</g' -e 's/>/>/g' )
;;
'/item')
cat<<EOF
<article>
<h3><a href="$link">$title</a></h3>
<p>$description
<span class="post-date">posted on <time
datetime="$datetime">$pubDate</time></span></p>
</article>
EOF
;;
esac
done