Skip to content

Instantly share code, notes, and snippets.

@kinduff
Last active March 25, 2016 00:16
Show Gist options
  • Select an option

  • Save kinduff/9f11f55148ec2905953e to your computer and use it in GitHub Desktop.

Select an option

Save kinduff/9f11f55148ec2905953e to your computer and use it in GitHub Desktop.
Mexican States and Cities Hash Generator - Hash Base de Datos para Estados y Ciudades de México
# encoding: UTF-8
require 'httparty'
require 'json'
states_and_cities = {}
32.times do |i|
next if i == 0 # skip cus first is trash
url = "http://inegifacil.com/cities/#{i}"
response = HTTParty.get(url)
hashes = JSON.parse(response.body)
state = hashes.shift["nombre_entidad"]
cities = hashes.map{|hash| hash["nombre_municipio"] }.unshift(state)
states_and_cities[state] = cities
end
print states_and_cities
@kinduff
Copy link
Author

kinduff commented May 6, 2015

Parse

states_and_cities.each do |state, cities|
  puts "+ #{state}"
  cities.each do |city|
    puts "  + #{city}"
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment