Skip to content

Instantly share code, notes, and snippets.

@chrjsorg
Last active August 29, 2015 13:57
Show Gist options
  • Save chrjsorg/9508213 to your computer and use it in GitHub Desktop.
Save chrjsorg/9508213 to your computer and use it in GitHub Desktop.
Prüft periodisch ob eine Prüfung/B-Aufgabe bereits benotet wurde.
#!/bin/env ruby
# encoding: utf-8
# Requirements: Ruby, Highline Gem, Mechanize Gem
require 'rubygems'
require 'mechanize'
require 'highline/import'
#Keep in mind, this setting is evil. But well..
I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG = nil
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
REFRESH_INTERVAL_SECONDS = 300
$wb_link = 'https://www.wb-online-campus.de/'
$username_field_id = 'j_username'
$password_field_id = 'j_password'
$username = 'YOUR_USERNAME'#ask('Username:') #alternativ 'USERNAME' ohne ask...
$password = 'YOUR_PASSWORD' #ask('Password:') { |q| #alternativ 'PASSWORD' ohne ask
#q.echo = '*'
#}
$modul_to_check = ask("B-Aufgabe/Modul? (B-BWR01XX, IMIPS -> Kurzname der Pruefung)")
$notenseitenlink = ""
$a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
agent.follow_meta_refresh = true
}
def login()
#Load login page
page = $a.get($wb_link)
#fill the form
login_form = page.forms[0]
username_field = login_form.field_with(:name => $username_field_id)
password_field = login_form.field_with(:name => $password_field_id)
username_field.value = $username
password_field.value = $password
#submit
main_page = login_form.submit
#after login page
#support only first course
zwischenpagelink = main_page.parser.xpath("//*[@id='start_left_Welcome']/div[4]/table/tbody/tr[1]/td[1]/a/@href").first
if(zwischenpagelink == nil)
puts "Login fehlgeschlagen"
Process.exit
end
studiengangseite = $a.get($wb_link << zwischenpagelink)
#get mark view link
notenuebersichtlink = studiengangseite.parser.xpath("//*[contains(@class, 'menured button')]/@onclick")
np_link = notenuebersichtlink.inner_html
#since its an onclick link and not a real link..
np_link = np_link[22..np_link.length]
#get mark overview page
$notenseitenlink = $wb_link << np_link
end
def check_for_grade()
#load final page
notenpage = $a.get($notenseitenlink)
rows = notenpage.parser.xpath('//table/tbody/tr')
#build hash out of mark table
grades = rows.collect do |row|
grade = {}
[
[:title, 'td[1]/a/text()'],
[:finalgrade, 'td[6]/text()'],
].each do |name, xpath|
grade[name] = row.at_xpath(xpath).to_s.strip
end
grade
end
modul_found = false
grades.each do|modul,finalgrade|
if(modul[:title].downcase == $modul_to_check.downcase)
modul_found = true
time = Time.new
puts "\nPruefung um " << time.strftime("%H:%M") << ": "
grade = modul[:finalgrade]
if(grade.length == 3) #1.0, 2.4, 3.3, ..., "zu benoten"
puts "Note vorhanden fuer " << modul[:title].upcase << ": " << grade
Process.exit
end
puts "Keine Benotung vorhanden. (" << $modul_to_check.upcase << ")"
end
end
if(modul_found == false)
puts "\nModul nicht gefunden."
Process.exit
end
end
login()
while true do
check_for_grade()
sleep(REFRESH_INTERVAL_SECONDS)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment