Skip to content

Instantly share code, notes, and snippets.

@mdciotti
Created December 15, 2012 00:36
Show Gist options
  • Save mdciotti/4290009 to your computer and use it in GitHub Desktop.
Save mdciotti/4290009 to your computer and use it in GitHub Desktop.
Scrape HAC for grades, uses an ugly hierarchical method that probably is broken right now
# casperjs ~/dev/scrape.coffee --ignore-ssl-errors=true
utils = require('utils')
casper = require('casper').create
remoteScripts: [
'//cdnjs.cloudflare.com/ajax/libs/zepto/1.0rc1/zepto.min.js'
]
verbose: true
logLevel: "debug"
loadImages: false
loadPlugins: false
x = casper.selectXPath
class Assignment
constructor: (@title, @score) ->
class Category
constructor: (@title, @weight) ->
assignments: []
addAssignment: (title, score) ->
@assignments.push new Assignment title, score
@
class MarkingPeriod
constructor: ->
officialScore: null
addCategory: (title, weight) ->
@categories.push new Category title, weight
@
class Semester
constructor: ->
officialScore: null
examScore: null
examWeight: 0.15
markingPeriodsPerSemester: 3
addMarkingPeriod: ->
@markingPeriods.push new MarkingPeriod
@
class Course
constructor: (@title, @teacher, @period) ->
semesters: []
semester: ->
@semester.push new Semester
@
class Student
constructor: (@name, @id, @school) ->
courses: []
addCourse: (title, teacher, period) ->
@courses.push new Course title, teacher, period
@
getStudents = ->
# document.querySelector "#ctl00_plnMain_dgStudents"
links = {}
$("#ctl00_plnMain_dgStudents a").each (i, el) ->
id = $(el).attr("href").substr -6, 6
links[id] =
name: el.innerHTML
url: $(el).attr "href"
links
parseGrades = ->
student = new Student
student.name = $("#_ctl0_tdMainContent .StudentName").text()
student.id = $("#_ctl0_tdMainContent .StudentName").text()
$classes = $("#_ctl0_tdMainContent .DataTable").first()
# There has got to be a better way to select these:
$classes.children().children(".DataRow").add(".DataRowAlt").each (i, row) ->
course = student.addCourse $(row).children().eq(0).text() $(row).children().eq(1).text() $(row).children().eq(2).text()
# course.addCategory
course.mpScores[0] = $(row).children().eq(3).text()
course.mpScores[1] = $(row).children().eq(4).text()
course.mpScores[2] = $(row).children().eq(5).text()
course.semesterScores[0] = $(row).children().eq(7).text()
course.examScores[0] = $(row).children().eq(6).text()
student
# Array.prototype.forEach.call tables, (table) ->
getGrades = ->
casper.open "https://accesscenter.roundrockisd.org/homeaccess/Student/Gradespeed.aspx?target=https://gradebook.roundrockisd.org/pc/displaygrades.aspx"
casper.then ->
classes = casper.evaluate parseGrades
@echo "start classes"
utils.dump classes
@echo "end classes"
casper.start "https://accesscenter.roundrockisd.org/homeaccess/", ->
@fill "form#aspnetForm",
"ctl00$plnMain$txtLogin": casper.cli.options["user"]
"ctl00$plnMain$txtPassword": casper.cli.options["pass"]
, false
@click "#ctl00_plnMain_Submit1"
casper.then ->
@echo "Page Title: #{@getTitle()}"
if @getTitle() is "My Students"
students = casper.evaluate getStudents
if casper.cli.options.hasOwnProperty "id"
# utils.dump students
student = students[casper.cli.options["id"]]
# utils.dump student
@click "a[href=\"#{student.url}\"]"
casper.then getGrades
else
@echo "Please provide a student identifier (--id=123456)", "ERROR"
@echo "#{id}: #{student.name}" for id, student of students
else
@echo "Single student"
# casper.thenOpen "https://accesscenter.roundrockisd.org/homeaccess/Student/Gradespeed.aspx?target=https://gradebook.roundrockisd.org/pc/displaygrades.aspx"
casper.then ->
# @echo @getCurrentUrl()
# @debugHTML()
casper.run ->
# @echo "done"
@exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment