-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathums.rb
executable file
·56 lines (44 loc) · 1.24 KB
/
ums.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
%w(nokogiri mechanize).each do |gem|
begin
require gem
rescue LoadError
puts "#{gem} not installed"
puts " `gem install #{gem}`"
exit
end
end
require 'open-uri'
begin
require './ums-config'
rescue LoadError
File.open('ums-config.rb', 'w') do |file|
file.puts 'USERNAME = ""'
file.puts 'PASSWORD = ""'
file.puts
end
puts '"ums-config.rb" config file created'
exit
end
agent = Mechanize.new
agent.get("https://ums.ulbsibiu.ro/ums/do/secure/inregistrare_user")
agent.page.forms[0]["j_username"] = USERNAME
agent.page.forms[0]["j_password"] = PASSWORD
agent.page.forms[0].submit
# change context
agent.page.links.find {|link| link.text[/context/]}.click
agent.page.links.find {|link| link.text[/Calculatoare/]}.click
# note
agent.page.links.find {|link| link.text[/Note/]}.click
links = agent.page.links.select {|link| link.href[/vizualizare_situatie_detaliata_evaluari/]}
links.each do |link|
page = agent.get(link.href)
parser = page.parser
title = parser.css("td.title_1").first
title = title.content.strip
title = title.split(' - ').last
nota = parser.css(".tabel_info td.celula_tabel_center").last
next unless nota
nota = nota.content.strip
puts "#{title}: #{nota}"
end