Last active
March 25, 2016 00:16
-
-
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
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
# 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 |
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
Result