Skip to content

Instantly share code, notes, and snippets.

@magentanova
Last active March 16, 2017 20:45
Show Gist options
  • Save magentanova/2a6b6fc094a2972a316d88fe42499fdf to your computer and use it in GitHub Desktop.
Save magentanova/2a6b6fc094a2972a316d88fe42499fdf to your computer and use it in GitHub Desktop.
Scrapes newline to create progress reports for a given cohort. Gems to install: mechanize and pry. Also, you must edit the file to add your login credentials
require 'mechanize'
require 'pry'
$email =
$password =
$group_url = "https://online.theironyard.com/admin/groups/249" #example: 'https://online.theironyard.com/admin/groups/80'
$path_url = "https://online.theironyard.com/admin/paths/930" #example: 'https://online.theironyard.com/admin/paths/333'
def all_count
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get("https://online.theironyard.com/admin/paths/my_paths") do |page|
# sign in here
new_page = page.form_with(id: "new_user") do |sign_in_form|
sign_in_form.field_with(id: "user_email").value = $email
sign_in_form.field_with(id: "user_password").value = $password
end.submit
student_urls = []
a.get($group_url) do |cohort_page|
cohort_page.search("#students table tbody tr").each do |student_row|
student_urls << student_row.search("td")[0].search("a")[0]["href"]
end
end
students = {}
a.get($path_url) do |path|
path.search(".assignment a.text-body").each do |node|
# test if assignment is in future and/or if hidden
a.get(node["href"]) do |assignment_page|
# Assignments must:
# 1) be public or current
# 2) Not start with "(" ---- because You can do (Optional) or (Challenge)
# 3) If a due date is assigned, it must be in the past
assignment_state = assignment_page.search("#state option[selected='selected']")[0].attributes["value"].value
acceptable = (["public", "current"].include? assignment_state) && !(node.text.start_with? "(")
begin
date_string = assignment_page.search(".col-md-4").last.search("p").last.text
date = Date.strptime(date_string, '%B %d, %Y') # June 01, 2016
acceptable = false if Date.today < date
rescue ArgumentError
# might not have a date set.
end
if acceptable
assignment_page.search("#submissions tbody tr").each do |student_row|
tds = student_row.search("td")
name = tds[0].text.strip
grade = tds[1].search("label")[0].text.strip
students[name] ||= {}
students[name][node.text] = grade
end
end
end
end
end
students.each do |student_name, assignments|
ok = ["Complete and unsatisfactory","Complete and satisfactory", "Exceeds expectations", "Not graded"]
ok_count = assignments.select {|name, grade| ok.include? grade }.count
percent = (ok_count.to_f / assignments.keys.count.to_f) * 100
puts "#{student_name.rjust(75)} - #{percent.round(0)}%"
puts 110.times.map {"-"}.join
assignments.each do |name, grade|
puts "#{name.chars.take(75).join("").rjust(75)} -> #{grade}"
end
5.times { puts }
end
end
end
all_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment