Skip to content

Instantly share code, notes, and snippets.

@huichops
Last active August 29, 2015 14:00
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 huichops/f2a768ecd3a1e651984f to your computer and use it in GitHub Desktop.
Save huichops/f2a768ecd3a1e651984f to your computer and use it in GitHub Desktop.
Script para parsear ofertas del siiau
Script para sacar los datos de la oferta academica del SIIAU
require 'nokogiri'
require 'open-uri'
def parse_profesor(element)
element.css('td').last.text
end
def parse_horario(element)
horarios_list = []
keys = %w[hora dias edificio aula fecha]
horarios = element.css('tr')
horarios.each do |horario|
horario_hash = {}
campos = horario.children[1..-1]
keys.each_with_index do |val, index|
horario_hash[val.to_sym] = campos[index].text
end
horarios_list.push horario_hash
end
horarios_list
end
def parsiiau(html)
lista_ofertas = []
keys = %w[nrc clave materia seccion creditos cupo disponible horario profesor]
ofertas = html.at_css('table').children[2..-1]
ofertas.each do |tr|
oferta = {}
campos = tr > 'td'
keys.each_with_index do |val, index|
if keys[index] == 'horario'
result = parse_horario campos[index]
elsif keys[index] == 'profesor'
result = parse_profesor campos[index]
else
result = campos[index].text
end
oferta[val.to_sym] = result
end
lista_ofertas.push oferta
end
lista_ofertas
end
# ejecutar ejemplo
#doc = Nokogiri::HTML.parse(open('http://t09.siiau.udg.mx/wco/sspseca.consulta_oferta?ciclop=201410&cup=D&mostrarp=5'))
#puts parsiiau doc
  1. Parseo de dias en horario
  2. Parseo de fecha en horario
  3. Tolerancia a fallos cuando hay campos vacios
  4. Tal vez sea necesario que sean objetos??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment