Don't like ads? PRO users don't see any ads ;-)
Guest

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
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'rubygems'
  2. require 'mechanize'
  3. require 'prowl'
  4.  
  5. @@asignaturas = {}
  6. p = Prowl.new(:apikey => "**************************", :application => "EUITT Grades")
  7.  
  8. while TRUE
  9.   agent = Mechanize.new
  10.  
  11.   page = agent.get("https://intra.euitt.upm.es/main/login/")
  12.   #page = agent.get("file:///home/blaid/proyectos/euitt/Escuela%20Universitaria%20de%20Ingenier%C3%ADa%20T%C3%A9cnica%20de%20Telecomunicaciones.html")
  13.   form = page.forms.first
  14.   form.field_with(:name => "user").value = "bofernan"
  15.   form.field_with(:name => "pass").value = "***********"
  16.   page = form.submit form.buttons.first
  17.  
  18.   page = page.link_with(:text => "Consulta de notas").click
  19.   asigs = page.parser.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "normal", " " )) and (((count(preceding-sibling::*) + 1) = 1) and parent::*)]//b').to_a     
  20.   notas = page.parser.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "normal", " " )) and (((count(preceding-sibling::*) + 1) = 2) and parent::*)]//b').to_a
  21.  
  22.   asigs.map!{|a| a.to_s.gsub!("<b>","").gsub!("</b>","")}
  23.   notas.map!{|n| n.to_s.scan(/\d,\d|No presentado/).first}
  24.  
  25.   asigs.each_with_index do |a,index|
  26.     if @@asignaturas[a]
  27.       @@asignaturas[a][:grade] = notas[index]
  28.     else
  29.       @@asignaturas[a] = {:grade => notas[index]}
  30.     end  
  31.   end
  32.  
  33.   @@asignaturas.each do |key,value|
  34.     if value[:grade] and !value[:notified]
  35.       puts "Asignatura: #{key} - #{value[:grade]}"
  36.       p.add(:event => "Nota publicada!", :description => "Has sacado un #{value[:grade]} en #{key}")
  37.       value[:notified] = true
  38.     end
  39.   end
  40.  
  41.   sleep(10)
  42. end