Created
          February 2, 2010 01:52 
        
      - 
      
 - 
        
Save flov/292275 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
flov revised this gist
Feb 2, 2010 . 2 changed files with 24 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ 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  - 
        
flov created this gist
Feb 2, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ require 'open-uri' require 'hpricot' (1...267).each do |x| open("http://www.couchsurfing.org/get_option_values.html?cpaint_function=get_states_auto&cpaint_argument[]=#{x}") do |f| f.first.split('#').collect{|i| i.split('|')}.each{|i| puts "country_id: #{x}, state_id: #{i[0]}, state: #{i[1]}"} end end