Skip to content

Instantly share code, notes, and snippets.

@guimello
Created November 16, 2010 18:50
Show Gist options
  • Save guimello/702264 to your computer and use it in GitHub Desktop.
Save guimello/702264 to your computer and use it in GitHub Desktop.
Capital codes (climatempo)
#!/usr/bin/env ruby
################################################################################
ENV["RAILS_ENV"] = ARGV[1] || 'development'
require File.dirname(__FILE__) + '/../config/environment'
require 'mechanize'
path = '/root/path'
File.open(File.join(path, 'climatempo.txt', 'w+')) do |f|
mechanize = Mechanize.new
(1..6000).each do |city_code|
puts "[#{Time.current}] Loop in #{city_code}" if [1000,2000,3000,4000,5000].include?(city_code)
mechanize.get("http://selos.climatempo.com.br/selos/selo.php?CODCIDADE=#{city_code}").save('/tmp/clima.xml')
d = Nokogiri::XML(File.open '/tmp/clima.xml')
next if d.blank?
if d.at_xpath('/selos/cidade')['nome'].match(/(Aracajú|Belém|Belo Horizonte|Boa Vista|Brasília|Campo Grande|Cuiabá|Curitiba|Florianópolis|Fortaleza|Goiânia|João Pessoa|Macapá|Maceió|Manaus|Natal|Palmas|Porto Alegre|Porto Velho|Recife|Rio Branco|Rio de Janeiro|Salvador|São Luís|São Paulo|Teresina|Vitória)$/)
f.puts city_code
puts "[#{Time.current}] CODCIDADE=#{city_code}+++"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment