Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Created July 7, 2011 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascaton/1070601 to your computer and use it in GitHub Desktop.
Save lucascaton/1070601 to your computer and use it in GitHub Desktop.
#
# Pra quem ficou com preguiça de ficar dando refresh na página da polícia
# federal na hora de solicitar o passaporte
#
require 'rubygems'
require 'net/http'
require 'uri'
cpf = "1234567890"
birthdate = "01%2F01%2F1985"
@cookie = nil
def post(url_string, data={})
headers = @cookie ? { 'Cookie' => @cookie, 'Content-Type' => 'application/x-www-form-urlencoded', 'Referer' => "http://www7.dpf.gov.br/sinpa/jsp/agenda/agendamento/paginaInicial.jsp" } : {}
url = URI.parse("http://www7.dpf.gov.br/sinpa/#{url_string}")
http = Net::HTTP.new(url.host, url.port)
http.post(url.path, data, headers)
end
# Clique aqui para começar
res = post("jsp/agenda/agendamento/paginaInicial.jsp")
@cookie = res.response['set-cookie']
# Formulario inicial
post('realizarAgendamento.do', "dispatcher=exibirSolicitacaoAgendamento&validate=false&postoId=")
# CAPTCHA
File.open("image.jpg", "w"){ |f| f.write post("jcaptcha.do").body }
print "Digite o captcha: "
captcha = gets.chomp
# Busca
post("realizarAgendamentoPrincipal.do", "dispatcher=processarConsultaAgendamento&validate=true&origem=exibirSolicitacaoAgendamento&cpf=#{cpf}&protocolo=&dataNascimento=#{birthdate}&operacao=agendar&senha=#{captcha}").body
# Verificar locais
arr = [
[1375, "Eldorado"],
[185, "Núcleo de passaportes"],
[1374, "Ibirapuera"],
[1376, "ABC"],
[1381, "Guarulhos"],
[1383, "Alpha"],
[1386, "Tatuapé"],
[1387, "Light"]
]
while true
arr.each do |id, name|
body = post("realizarAgendamento.do", "dispatcher=exibirInclusaoAgendamento&postoId=#{id}&validate=false").body
if body.scan("Consulte outro posto").empty?
puts body
raise "#{name}: Tem vaga!! GO GO GO!!\n"
else
puts "#{name}: :("
end
end
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment