summaryrefslogtreecommitdiff
path: root/sfeed_opml_export
blob: eb225205cdcf2628b8fa84ff418546330969ae28 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

# load config (evaluate shellscript).
# loadconfig(configfile)
loadconfig() {
	# allow to specify config via argv[1].
	if [ "$1" != "" ]; then
		# get absolute path of config file required for including.
		config="$1"
		path=$(readlink -f "${config}" 2>/dev/null)
	else
		# default config location.
		config="$HOME/.sfeed/sfeedrc"
		path="${config}"
	fi

	# config is loaded here to be able to override $sfeedpath or functions.
	if [ -r "${path}" ]; then
		. "${path}"
	else
		echo "Configuration file \"${config}\" cannot be read." >&2
		echo "See sfeedrc.example for an example." >&2
		exit 1
	fi
}

# override feed function to output OPML XML.
# feed(name, feedurl, [basesiteurl], [encoding])
feed() {
	# TABs, newlines and echo options in field values are not checked.
	echo "$1	$2"
}

# load config file.
loadconfig "$1"

cat <<!
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
	<title>OPML export from sfeed</title>
</head>
<body>
!

feeds | awk -F '\t' '{
	gsub("&", "\\&amp;");
	gsub("\"", "\\&quot;");
	gsub("'"'"'", "\\&#39;");
	gsub("<", "\\&lt;");
	gsub(">", "\\&gt;");

	print "\t<outline type=\"rss\" title=\"" $1 "\" text=\"" $1 "\" xmlUrl=\"" $2 "\"/>";
}'

cat <<!
</body>
</opml>
!