Skip to content

Instantly share code, notes, and snippets.

@ik5 ik5/to_config.rb
Created Jan 31, 2014

Embed
What would you like to do?
Converting planet's html to planets.ini file
#!/usr/bin/env ruby
# encofing: utf-8
require 'rubygems'
require 'nokogiri'
page = Nokogiri::HTML(open('/tmp/planetfossil.htm'))
feeds = Hash.new
page.css('li').each do |el|
name = ''
feed = ''
el.children.each do |a|
next if a.attributes.empty?
attr = a.attributes
# where the title exists, we do not have the feed
if attr.key? 'title'
name = attr['title'].value
else # we have the feed on the next
feed = attr['href'].value
end
end
feeds[name] = feed
end
f = open('config.ini', 'w')
feeds.each_pair do |k,v|
f.puts "[#{v}]"
f.puts "name = #{k}"
f.puts
end
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.