Skip to content

Instantly share code, notes, and snippets.

@ik5
Created January 31, 2014 15:22
Show Gist options
  • Save ik5/8734056 to your computer and use it in GitHub Desktop.
Save ik5/8734056 to your computer and use it in GitHub Desktop.
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