Created
January 31, 2014 15:22
-
-
Save ik5/8734056 to your computer and use it in GitHub Desktop.
Converting planet's html to planets.ini file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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