Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save seyyah/5823364 to your computer and use it in GitHub Desktop.
Save seyyah/5823364 to your computer and use it in GitHub Desktop.
# encoding: UTF-8
#
# UBS'de girilen içerik EBS üzerinden webde görülebilmektedir. Bu betik
# yardımıyla Bilgisayar Mühendisliği Bölümü'ne ait tüm derslerin içerik tek bir
# html dosya olarak üretilmektedir. Ayrıca içeriği eksik olan derslere ait
# raporlar üretilmektedir.
#
# Usage:
# $ ruby ders-icerigi-ve-eksik-icerik-belirleme-ebs-yardimiyla.rb
#
# Note:
# EBS arayüzü değiştirilirse BASE_URL altında ki `uri`'yi kontrol ederek
# başlamak gerek, değişikliğe.
require 'nokogiri'
require 'open-uri'
require 'pp'
require 'csv'
require 'roman_numerals_converter'
require 'roo'
$course_keys = ['level', 'objective', 'lecture', 'outcomes', 'delivery',
'prerequisities', 'component', 'reading', 'learning',
'language', 'work', 'content', 'detailed_content',
'assessment', 'workload']
def get_course_info(doc)
keys = ['code', 'name', 'type', 'year', 'term', 'ects']
info = {}
doc.css('.AltSatir > td').each_with_index do |d, i|
info[keys[i]] = d.content
end
info
end
def get_course_detail(doc)
detail = {}
doc.css('#icerik .keyContainer .Value').each_with_index do |d, i|
detail[$course_keys[i]] = d.content
end
detail
end
def get_department_courses(doc)
keys = ['link', 'name', 'type', 'theoretical', 'practice', 'laboratory', 'ects']
courses = {}
doc.css('.ptProgramTanimlari.section .ders').each_with_index do |d, i|
code = d.at_xpath('td[1]/a/text()').content.strip.to_sym
course = {uri: d.at_xpath('td[1]/a')['href'],
code: code,
name: d.at_xpath('td[2]/text()').content,
type: d.at_xpath('td[3]/text()').content,
theoratical: d.at_xpath('td[4]/text()').content,
practice: d.at_xpath('td[5]/text()').content,
laboratory: d.at_xpath('td[6]/text()').content,
ects: d.at_xpath('td[7]/text()').content }
if courses.has_key?(code)
courses[code] << course
else
courses[code] = [course]
end
end
courses
end
def status2sign(status)
status ? 'E' : 'H'
end
def report(uri, lang)
doc = Nokogiri::HTML(open(uri))
courses = get_department_courses(doc)
mufredat = {}
course_status = {}
courses.each do |code, ncourse|
ncourse.each do |course|
code = course[:code]
p "Code: '#{code}' isleniyor...\n"
uri = BASE_URL + course[:uri]
doc = Nokogiri::HTML(open(uri))
info = get_course_info(doc)
detail = get_course_detail(doc)
status = {final: (detail['objective'].empty? and detail['content'].empty? and detail['detailed_content'].empty?)}
$course_keys.each do |k|
status[k.to_sym] = !detail[k].empty?
end
if status[:final]
course_status[code] ||= status
next
else
course_status[code] = status
end
t, p, l = course[:theoratical], course[:practice], course[:laboratory]
str = "<h3>#{info['code']} #{info['name']} #{t}-#{p}-#{l} AKTS: #{info['ects']}</h3>\n"
if status[:content]
str += "<p>#{detail['content']}</p>"
else
str += "<p>#{detail['objective']}</p>"
end
unless detail['reading'].empty?
str += "<h4>Kaynaklar</h4>\n"
str += "<p>#{detail['reading']}</p>"
end
y, t = info['year'], info['term']
if mufredat[y].nil?
mufredat[y] = {}
end
if mufredat[y][t].nil?
mufredat[y][t] = "#{str}<hr>"
else
mufredat[y][t] += "#{str}<hr>"
end
end
end
fnm = "/tmp/courses_problematic_#{lang}.csv"
CSV.open(fnm, 'w') do |csv|
r = ['Code', 'Name']
$course_keys.each do |k|
r << k.to_s
end
csv << r
course_status.each do |code, status|
if status[:final]
r = [code, courses[code][0][:name]]
$course_keys.each do |k|
r << status2sign(status[k.to_sym])
end
csv << r
end
end
end
p "Problemli dersler '#{fnm}' icerisine saklandi."
fnm = "/tmp/courses_status_#{lang}.csv"
CSV.open(fnm, 'w') do |csv|
r = ['Code', 'Name']
$course_keys.each do |k|
r << k.to_s
end
csv << r
course_status.each do |code, status|
r = [code, courses[code][0][:name]]
$course_keys.each do |k|
r << status2sign(status[k.to_sym])
end
csv << r
end
end
p "Bölümün tüm derslerinin durumu '#{fnm}' icerisine saklandi."
fnm = "/tmp/ders_icerikleri_#{lang}.html"
fp = File.new(fnm, 'w')
str = "<h1>OMÜ Bilgisayar Mühendisliği Bölümü</h1>"
(1..8).each do |yy|
y = (yy - 1)/2 + 1
str += "<h2>#{yy.to_roman}. YARIYIL (#{yy%2==1 ? 'GÜZ' : 'BAHAR'} DÖNEMİ)</h2>"
str += mufredat[y.to_s][yy.to_s]
end
fp.write(str)
fp.close
p "Ders icerikleri '#{fnm}' icerisine saklandi."
end
# Ana program
BASE_URL = "http://ebs.omu.edu.tr/ebs/"
uri_tr = BASE_URL + "program.php?dil=tr&mod=1&Program=2727&o=M%C3%9CHEND%C4%B0SL%C4%B0K+FAK%C3%9CLTES%C4%B0+%2F+B%C4%B0LG%C4%B0SAYAR+M%C3%9CHEND%C4%B0SL%C4%B0%C4%9E%C4%B0+B%C3%96L%C3%9CM%C3%9C"
uri_en = BASE_URL + "program.php?dil=en&mod=1&Program=2727&o=FACULTY%20OF%20ENGINEERING%20/%20COMPUTER%20ENGINEERING"
report(uri_tr, 'tr')
report(uri_en, 'en')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment