Created
February 2, 2010 01:52
-
-
Save flov/292275 to your computer and use it in GitHub Desktop.
This file contains 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
require 'open-uri' | |
require 'yaml' | |
h={} | |
(1..267).each do |x| | |
open("http://www.couchsurfing.org/get_option_values.html?cpaint_function=get_states_auto&cpaint_argument[]=#{x}") do |f| | |
if f.first | |
# anybody knows why it doesnt check if the string is empty before it executes the split ??? | |
# I went through all x which dont work and substitude f.first with | |
# x!=112 and x!=122 and x!=124 and x!= 150 and x!=219 and x!= 240 | |
# which works. Pretty weird! | |
f.first.split('#').collect{|i| i.split('|')}.each do |i| | |
h["state_#{i[0]}"]={} | |
h["state_#{i[0]}"]["id"] = i[0] | |
h["state_#{i[0]}"]["state_id"] = i[1] | |
h["state_#{i[0]}"]["country_id"] = x | |
puts "country_id: #{x}, state_id: #{i[0]}, state: #{i[1]}" | |
end | |
end | |
end | |
end | |
File.open('states.yml', 'w') do |f| | |
f.write(h.to_yaml) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment