-
Notifications
You must be signed in to change notification settings - Fork 7
/
opml.rb
52 lines (40 loc) · 946 Bytes
/
opml.rb
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
#####
# generate feed list in opml (xml) format from ini
require 'iniparser' ## 3rd party gem - use $ gem install iniparser
require 'date' ## stdlibs
require 'time'
require 'cgi'
def escape(text) CGI::escapeHTML( text ); end
path = ARGV[0] || './planet.ini'
hash = INI.load_file( path )
head = ""
body = ""
hash.each do |k,v|
if v.is_a?( String )
if k == 'title'
head << " <title>#{escape(v)}</title>"
else
STDERR.puts "!! WARN - skipping unknown property >#{k}< >#{v}<"
end
else ## assume value is Hash
line = " "
line << "<outline"
line << " text=\"#{escape(k)}\""
line << " xmlUrl=\"#{escape(v['feed'])}\""
line << "/>"
body << "\n" unless body.empty?
body << line
end
end
xml =<<XML
<opml version="1.1">
<head>
#{head}
<dateModified>#{Time.now.utc.rfc822}</dateModified>
</head>
<body>
#{body}
</body>
</opml>
XML
puts xml