Created
June 14, 2012 16:28
-
-
Save xoebus/2931327 to your computer and use it in GitHub Desktop.
Get your UoE Exam Grades - MEGA HACKY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get your UoE grades. | |
# Usage: ruby grades.rb <username> <password> | |
require 'mechanize' | |
require 'terminal-table' | |
require 'rainbow' | |
agent = Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
page = agent.get("https://www.myed.ed.ac.uk/uPortal/tag.idempotent.render.u203903l1n56.uP?") | |
login_form = page.form_with("action" => "/cosign.cgi") | |
login_form.login = ARGV[0] | |
login_form.password = ARGV[1] | |
page = agent.submit(login_form, login_form.buttons.first) | |
page = agent.click(agent.page.link_with(:text => "Studies")) | |
table = agent.page.search('table.uportal-channel-table').first | |
courses = table.search('//tr/td/a')[0..-3].map do |a| | |
a.text.gsub("\n", " ").gsub(/^ /, "") | |
end.select { |e| e != "" } | |
marks = [] | |
table.search('//tr/td')[1..252].map { |a| a.text.gsub("\n", " ") }.each_with_index do |e,i| | |
marks << e if (i-4) % 7 == 0 | |
end | |
results = courses.zip(marks) | |
table = Terminal::Table.new :headings => ["Course".color(:red), "Mark".color(:blue)] | |
table.align_column(1, :right) | |
c = false | |
results.each do |a,b| | |
col = c ? :green : :blue | |
table << [a.color(col), b.color(col)] | |
c = !c | |
end | |
puts table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment