-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_opml.rb
58 lines (32 loc) · 1.07 KB
/
convert_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
53
54
55
56
57
# encoding: utf-8
require 'logutils'
require 'fetcher'
require 'feedutils'
require 'active_support/all' # for Hash.from_xml
### our own code
require './config'
puts "hello from converting planet config"
logger = LogUtils::Logger.root
logger.level = :debug
def fetch_opml( opml_str )
worker = Fetcher::Worker.new
res = worker.get_response( opml_str )
puts "#{res.code} #{res.message}"
if res.code != '200' # Note: res.code (HTTP status code) is a string
puts "sorry; failed to fetch opml feed"
exit(1)
end
xml = res.body
###
# Note: Net::HTTP will NOT set encoding e.g. to UTF-8 etc.
# will be ASCII; change encoding to UTF-8
xml = xml.force_encoding( Encoding::UTF_8 )
end
# 'http://planet.mozilla.org/opml.xml'
# 'http://blogs.openstreetmap.org/opml.xml'
# Note: Ruby's first program argument is zero e.g. ARGV[0]
opml_str = ARGV[0] || 'http://blogs.openstreetmap.org/opml.xml'
xml = fetch_opml( opml_str )
planet = OpmlBuilder.build( xml )
planet.update ## fetch all feeds and update titles etc.
planet.save_file( 'planet.ini' )