Created
November 16, 2010 18:50
-
-
Save guimello/702264 to your computer and use it in GitHub Desktop.
Capital codes (climatempo)
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 characters
#!/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