
Script para mirar las notas en la intra de la EUITT
By: a guest on
Jun 13th, 2012 | syntax:
Ruby | size: 1.59 KB | hits: 23 | expires: Never
require 'rubygems'
require 'mechanize'
require 'prowl'
@@asignaturas = {}
p = Prowl.new(:apikey => "**************************", :application => "EUITT Grades")
while TRUE
agent = Mechanize.new
page = agent.get("https://intra.euitt.upm.es/main/login/")
#page = agent.get("file:///home/blaid/proyectos/euitt/Escuela%20Universitaria%20de%20Ingenier%C3%ADa%20T%C3%A9cnica%20de%20Telecomunicaciones.html")
form = page.forms.first
form.field_with(:name => "user").value = "bofernan"
form.field_with(:name => "pass").value = "***********"
page = form.submit form.buttons.first
page = page.link_with(:text => "Consulta de notas").click
asigs = page.parser.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "normal", " " )) and (((count(preceding-sibling::*) + 1) = 1) and parent::*)]//b').to_a
notas = page.parser.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "normal", " " )) and (((count(preceding-sibling::*) + 1) = 2) and parent::*)]//b').to_a
asigs.map!{|a| a.to_s.gsub!("<b>","").gsub!("</b>","")}
notas.map!{|n| n.to_s.scan(/\d,\d|No presentado/).first}
asigs.each_with_index do |a,index|
if @@asignaturas[a]
@@asignaturas[a][:grade] = notas[index]
else
@@asignaturas[a] = {:grade => notas[index]}
end
end
@@asignaturas.each do |key,value|
if value[:grade] and !value[:notified]
puts "Asignatura: #{key} - #{value[:grade]}"
p.add(:event => "Nota publicada!", :description => "Has sacado un #{value[:grade]} en #{key}")
value[:notified] = true
end
end
sleep(10)
end