Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Created February 27, 2017 13:06
Show Gist options
  • Save uyjulian/d30294c00012bc085dbbcc5369fd7cf3 to your computer and use it in GitHub Desktop.
Save uyjulian/d30294c00012bc085dbbcc5369fd7cf3 to your computer and use it in GitHub Desktop.
--This script grabs shit from renweb
--You can run this script at an interval (example: 30 seconds) to log every 30 seconds
--After that you can pack the log directory with zpaq or other archiver
--example:
--while true; do moon printstatus.moon; zpaq a /mnt/torrents3/log.zpaq log; sleep 30; done
--i wrote this script hastily, so it looks ugly right now
--password form: https://xxxxxxx.client.renweb.com/pw/index.cfm
--form data: DistrictCode=xxxxxxx&username=redacted&password=redacted&UserType=PARENTSWEB-STUDENT&login=Login
--can be compressed
--full curl: curl 'https://xxxxxxx.client.renweb.com/pw/index.cfm' -H 'Cookie: CFID=xxx; CFTOKEN=xxx; LB-Persist=!xxx; _gat=x; _ga=GAx.x.xxxxx.xxxxx' -H 'Origin: https://xxxxxxx.client.renweb.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,es;q=0.6,ja;q=0.4' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: xxx' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: https://xxxxxxx.client.renweb.com/pw/index.cfm' -H 'Connection: keep-alive' --data 'DistrictCode=xxxxxxx&username=redacted&password=redacted&UserType=PARENTSWEB-STUDENT&login=Login' --compressed
--important cookies to keep: CFID; CFTOKEN; LB-Persist
--no cookie/expired? 302'd back to https://xxxxxxx.client.renweb.com/pw/
--Homework list (monthly) (full): https://xxxxxxx.client.renweb.com/pw/school/calendar-print.cfm?filter=Homework&studentid=&view=list&month=1&year=1984&day=1&range=month
--Gtko link: https://xxxxxxx.client.renweb.com/pw/?LogOut=1
--Grade book progress report (aka per class/quarter grade): https://xxxxxxx.client.renweb.com/RenWeb/Reports/Gradebook/GradeBookProgressReport-PW.cfm?District=xxxxxxx&StudentID=1234567890&ClassID=1234567890&TermID=4&SchoolCode=xxxxxxx&Sessionid=892781CD-7DA4-44FA-AA39-1F5A873CCF7B&ReportHash=93F349209E2125C0DF599B5F3B7A5F22&hashval=93F349209E2125C0DF599B5F3B7A5F22
--all args are on https://xxxxxxx.client.renweb.com/pw/student/grades.cfm:
-- <input type="hidden" name="District" value="xxxxxxx" />
-- <input type="hidden" name="ReportType" value="Gradebook" />
-- <input type="hidden" name="sessionid" value="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx" />
-- <input type="hidden" name="ReportHash" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
-- <input type="hidden" name="SchoolCode" value="xxxxxxx" />
-- <input type="hidden" name="StudentID" value="1234567890" />
-- <input type="hidden" name="ClassID" value="1234567890" />
-- <input type="hidden" name="TermID" value="1" />
--lesson plans: https://xxxxxxx.client.renweb.com/pw/student/lesson-plans-print.cfm?studentid=1234567890&weekof=1/1/1984
gradeListParse = (str) ->
progressReportCapture = '<form action="/renweb/reports/parentsweb/parentsweb_reports.cfm" method="get" target="_blank" id="gradebook_[%d_]*" />' ..
'[%s\t]*<input type="hidden" name="District" value="XXXXXXX" />' ..
'[%s\t]*<input type="hidden" name="ReportType" value="Gradebook" />' ..
'[%s\t]*<input type="hidden" name="sessionid" value="([%d%u%-]*)" />' ..
'[%s\t]*<input type="hidden" name="ReportHash" value="([%d%u]*)" />' ..
'[%s\t]*<input type="hidden" name="SchoolCode" value="XXXXXXX" />' ..
'[%s\t]*<input type="hidden" name="StudentID" value="(%d*)" />' ..
'[%s\t]*<input type="hidden" name="ClassID" value="(%d*)" />' ..
'[%s\t]*<input type="hidden" name="TermID" value="(%d*)" />' ..
'[%s\t]*</form>'
si = {}
si.classes = {}
for sessionid, reporthash, studentid, classid, termid in str\gmatch(progressReportCapture)
si.sessionid = sessionid
si.reporthash = reporthash
si.studentid = studentid
table.insert(si.classes, {
classid: classid
termid: termid
})
return si
gradeParse = (str) ->
classInfoCapture = '<table width="600" style="border%-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">' ..
'[%s\t]*<tr>' ..
'[%s\t]*<td colspan="3" align="center" style="border%-style: none; border%-width: medium">' ..
'[%s\t]*<div style="border%-bottom%-style: solid; border%-bottom%-width: 1; padding%-bottom: 1">' ..
'[%s\t]*<p align="center"><b>' ..
'[%s\t]*<font size="5" face="Arial">Grade Book Student Progress Report</font></b></div>' ..
'[%s\t]*</td ></tr>' ..
'[%s\t]*<tr><td align="left" style="border%-style: none; border%-width: medium" >' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></td>' .. --student's name
'[%s\t]*<td align="center" style="border%-style: none; border%-width: medium">' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></td>' .. --year(s)
'[%s\t]*<td align="right" style="border%-style: none; border%-width: medium">' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></td></tr>' .. --teacher's name
'[%s\t]*<tr><td align="left" style="border%-style: none; border%-width: medium">' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></td>' .. --shorten class name
'[%s\t]*<td align="center" style="border%-style: none; border%-width: medium">' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></td>' .. --quarter
'[%s\t]*<td style="border%-style: none; border%-width: medium"><p align="right">' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></td></tr>' .. --grading type
'[%s\t]*<tr>' ..
'[%s\t]*<td colspan="3" align="left" style="border%-style: none; border%-width: medium">' ..
'[%s\t]*<div style="border%-bottom%-style: solid; border%-bottom%-width: 1; padding%-bottom: 1">' ..
'[%s\t]*<font face="Arial"><b>(.*)</b></font></div>' .. --full class name
'[%s\t]*</td ></tr>' ..
'[%s\t]*</table>'
catagoryCapture = '<table width="600" style="border%-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">' ..
'[%s\t]*<tr>' ..
'[%s\t]*<td style="border%-bottom%-style: solid; border%-bottom%-width: 1">&nbsp;</td>' ..
'[%s\t]*<td style="border%-bottom%-style: solid; border%-bottom%-width: 1">&nbsp;</td>' ..
'[%s\t]*<td style="border%-bottom%-style: solid; border%-bottom%-width: 1">&nbsp;</td></tr>' ..
'[%s\t]*<tr>' ..
'[%s\t]*<td align="center" style="border%-bottom%-style: solid; border%-bottom%-width: 1; border%-top%-style:solid; border%-top%-width:1"><b>' ..
'[%s\t]*<font face="Arial" size="2">(.-)</font></b></td>' .. --catname1
'[%s\t]*<td align="center" style="border%-bottom%-style: solid; border%-bottom%-width: 1; border%-top%-style:solid; border%-top%-width:1"><b>' ..
'[%s\t]*<font face="Arial" size="2">(.-)</font></b></td>' .. --catname2
'[%s\t]*<td align="center" style="border%-bottom%-style: solid; border%-bottom%-width: 1; border%-top%-style:solid; border%-top%-width:1"><b>' ..
'[%s\t]*<font face="Arial" size="2">Weight = ([%d%.]*)</font></b></td></tr>' .. --weigh
'[%s\t]*</table>' ..
'[%s\t]*<table width="600" style="border%-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">' ..
'[%s\t]*<tr><td align="left"><b><font size="1" face="Arial">Assignment</font></b></td>' ..
'[%s\t]*<td align="center">' ..
'[%s\t]*<b><font size="1" face="Arial">Pts</font></b></td>' ..
'[%s\t]*<td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Max</font></b></td><td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Avg</font></b></td><td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Status</font></b></td>' ..
'[%s\t]*<td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Due</font></b></td><td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Curve</font></b></td>' ..
'[%s\t]*<td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Bonus</font></b></td>' ..
'[%s\t]*<td align="center"><b>' ..
'[%s\t]*<font size="1" face="Arial">Penalty</font></b></td>' ..
'[%s\t]*<td align="left"><b>' ..
'[%s\t]*<font size="1" face="Arial">Weight</font></b></td>' ..
'[%s\t]*<td align="left"><b>' ..
'[%s\t]*<font size="1" face="Arial">Note</font></b></td></tr>' ..
'[%s\t]*(.-)' .. --all the gradez
'[%s\t]*<tr><td>' ..
'[%s\t]*<p align="left"><b><font size="2" face="Arial">Category Average</font></b></td><td>' ..
'[%s\t]*<p align="center"><b>' ..
'[%s\t]*<font size="2" face="Arial">' ..
'[%s\t]*([%d%.]*)' .. --the average
'[%s\t]*</font></b></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>'
assignmentCapture = '<tr>' ..
'[%s\t]*<td align="left"><font size="1" face="Arial">(.-)</font></td>' .. --assignment
'[%s\t]*<td align="center"><?f?o?n?t? ?s?i?z?e?=?"?1?"? ?f?a?c?e?=?"?A?r?i?a?l?"? ?c?o?l?o?r?=?"?B?l?a?c?k?"?>?%s*([%d%.]*)<?/?f?o?n?t?>?</td>' .. --pts
'[%s\t]*<td align="center"><?f?o?n?t? ?s?i?z?e?=?"?1?"? ?f?a?c?e?=?"?A?r?i?a?l?"? ?c?o?l?o?r?=?"?B?l?a?c?k?"?>?%s*([%d%.]*)<?/?f?o?n?t?>?</td>' .. --max
'[%s\t]*<td align="center"><?f?o?n?t? ?s?i?z?e?=?"?1?"? ?f?a?c?e?=?"?A?r?i?a?l?"? ?c?o?l?o?r?=?"?B?l?a?c?k?"?>?%s*([%d%.]*)<?/?f?o?n?t?>?</td>' .. --avg
'[%s\t]*<td align="center"><font size="1" face="Arial" color="Black">(.-)</font></td>' .. --status
'[%s\t]*<td align="center"><font size="1" face="Arial" color="Black">([%d/]*)</font></td>' .. --due
'[%s\t]*<td align="center"><font size="1" face="Arial" color="Black">([%d%.]*)</font></td>' .. --curve
'[%s\t]*<td align="center"><font size="1" face="Arial" color="Black">([%d%.]*)</font></td>' .. --bonus
'[%s\t]*<td align="center"><font size="1" face="Arial" color="#FF0000">(.-)</font></td>' .. --penalty
'[%s\t]*<td align="center"><font size="1" face="Arial" color="Black">([%d%.]*)</font></td>' .. --weight
'[%s\t]*<td align="left"><font size="1" face="Arial" color="Black">(.-)</font></td>' .. --note
'[%s\t]*</tr>'
termGradeCapture = '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>' ..
'[%s\t]*<tr><td><b><font size="2" face="Arial">Term Grade</font></b></td><td>' ..
'[%s\t]*<b><font size="2" face="Arial" >' ..
'[%s\t]*([%d%.]*)' ..
'[%s\t]*</font></b></td><td>' ..
'[%s\t]*<b>' ..
'[%s\t]*<font size="2" face="Arial" >(%u*)</font></b></td>' ..
'[%s\t]*<td></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>' ..
'[%s\t]*</tr>'
studentName, years, teacherName, shortClassName, quarter, gradingType, fullClassName = str\match(classInfoCapture)
termGrade, termLetter = str\match(termGradeCapture)
info = {
studentName: studentName
years: years
teacherName: teacherName
shortClassName: shortClassName
quarter: quarter
gradingType: gradingType
fullClassName: fullClassName
termGrade: termGrade
termLetter: termLetter
catagories: {}
}
for catname1, catname2, weigh, gradeinfo, average in str\gmatch(catagoryCapture)
catinfo = {
catname1: catname1
catname2: catname2
weigh: weigh
assignments: {}
average: average
}
for assignment, pts, max, avg, status, due, curve, bonus, penalty, weight, note in gradeinfo\gmatch(assignmentCapture)
table.insert(catinfo.assignments, {
assignment: assignment
pts: pts
max: max
avg: avg
status: status
due: due
curve: curve
bonus: bonus
penalty: penalty
weight: weight
note: note
})
table.insert(info.catagories, catinfo)
return info
lessonPlansParse = (str) ->
lessonPlansDayCapture = '<li class="dateli">' ..
'[%s\t]*<div class="datehw">([%d/]*) %- (.-)</div>' .. -- date mm/dd/yy, day of the week
'[%s\t]*(.-)' .. --all homework_items
'[%s\t]*</li>'
homeworkItemCapture = '<div class="homework_item"><span class="hwclass">(.-) %-</span> (.-)</div>' --class, item
days = {}
for date, day, items in str\gmatch(lessonPlansDayCapture)
dat = {
date: date
day: day
items: {}
}
for classs, item in items\gmatch(homeworkItemCapture)
table.insert(dat.items, {
class: classs
item: item\gsub("<br>", "\n")
})
table.insert(days, dat)
return days
homeworkCalendarParse = (str) ->
homeworkCalendarCapture = '<tr>' ..
'[%s\t]*<td>([%d/]*)</td>' .. --date mm/dd/yy
'[%s\t]*<td>(.-)</td>' .. --day of the week (monday, tuesday, wednesday, etc)
'[%s\t]*<td>' ..
'[%s\t]*<div class="evt_title with_link"><span class="homework%-student">(.-)</span>: <span class="homework%-class">(.-)</span><div class="homework%-describe">(.-)</div></div>' .. --student, class, description
'[%s\t]*<div class="evt_msg">' ..
'[%s\t]*<div><strong>Description:</strong><br />(.-)</div> ' .. --description2
'[%s\t]*</div>' ..
'[%s\t]*</td>'
hwcal = {}
for date, day, student, classs, description, description2 in str\gmatch(homeworkCalendarCapture)
table.insert(hwcal, {
date: date
day: day
student: student
class: classs
description: description\gsub("<br />", "\n")
--description2: description2
})
return hwcal
file_util = require"file_util"
serpent = require"serpent"
url_util = require"url_util"
thread = require"thread"
JSON = require"JSON"
thread_get = (url, args, parser) ->
blob = url_util.curl_read_url(url, args)
if parser
return parser(blob), blob
return blob
curl = require"cURL"
onions = {}
canthread = (func, url, options) ->
qwergyui = {}
lala = {}
qwergyui.join = ->
return func()
return qwergyui
-- print(serpent.block(gradeListParse(file_util.readfile("gradeslist_ex.html"))))
-- print(serpent.block(gradeParse(file_util.readfile("grades_ex.html"))))
-- print(serpent.block(lessonPlansParse(file_util.readfile("lessonplans_ex.html"))))
-- print(serpent.block(homeworkCalendarParse(file_util.readfile("homework_calendar_list_ex.html"))))
-- os.exit(0)
file = io.popen(file_util.shellargs("curl", "-s", "-X", "POST", "--cookie-jar", "-", "https://xxxxxxx.client.renweb.com/pw/index.cfm", "--data", "DistrictCode=xxxxxxx&username=redacted&password=redacted&UserType=PARENTSWEB-STUDENT&login=Login", "--compressed"), "r")
lbpersist = nil
cfid = nil
cftoken = nil
for line in file\lines!
--print(line)
if line\sub(1, 25) == "xxxxxxx.client.renweb.com"
strt, ennd = line\find("LB-Persist\t", 1, true)
if strt
lbpersist = line\sub(ennd + 1)
elseif line\sub(1, 26) == ".xxxxxxx.client.renweb.com"
strt, ennd = line\find("CFID\t", 1, true)
if strt
cfid = line\sub(ennd + 1)
strt, ennd = line\find("CFTOKEN\t", 1, true)
if strt
cftoken = line\sub(ennd + 1)
cookie = "CFID=" .. cfid .. "; CFTOKEN=" .. cftoken .. "; LB-Persist=" .. lbpersist
gradeslistblob = url_util.curl_read_url("https://xxxxxxx.client.renweb.com/pw/student/grades.cfm", {
ACCEPT_ENCODING: "gzip"
COOKIE: cookie
})
file_util.writefile("log/gradeslistblob.html", gradeslistblob)
alllsgr = gradeListParse(gradeslistblob)
get_days_in_month = (mnth, yr) ->
return os.date('*t',os.time{year:yr,month:mnth+1,day:0})['day']
yrs = {1984, 1985}
hwcalurls = {}
lessonplanurls = {}
for i, y in pairs(yrs)
for m = 1, 12
table.insert(hwcalurls, {"https://xxxxxxx.client.renweb.com/pw/school/calendar-print.cfm?filter=Homework&view=list&month=" .. m .. "&year=" .. y .. "&range=month", m .. "*" .. y .. "hwcal.html"})
d = get_days_in_month(m,y)
d7 = math.floor(d / 7)
for w = 1, d7
if alllsgr.studentid
table.insert(lessonplanurls, {"https://xxxxxxx.client.renweb.com/pw/student/lesson-plans-print.cfm?studentid=" .. alllsgr.studentid .. "&weekof=" .. m .. "/" .. w*7 .. "/" .. y, m .. "*" .. w .. "*" .. y .. "lessonplan.html"})
--gradeths = {}
optionall = {}
asdasdasdasd = {}
for i, v in pairs(alllsgr.classes)
handle = curl.easy(mytable)
mytable = {
URL: "https://xxxxxxx.client.renweb.com/renweb/reports/parentsweb/parentsweb_reports.cfm?District=xxxxxxx&ReportType=Gradebook&sessionid=" .. alllsgr.sessionid .. "&ReportHash=" .. alllsgr.reporthash .. "&SchoolCode=xxxxxxx&StudentID=" .. alllsgr.studentid .. "&ClassID=" .. v.classid .. "&TermID=" .. v.termid
ACCEPT_ENCODING: "gzip"
COOKIE: "LB-Persist=" .. lbpersist
FOLLOWLOCATION: 1
}
for i, v in pairs(mytable)
handle["setopt_" .. i\lower()](handle, v)
table.insert(optionall, mytable)
table.insert(asdasdasdasd, v.classid .. "*" .. v.termid)
-- table.insert(gradeths, {canthread(thread_get, "https://xxxxxxx.client.renweb.com/renweb/reports/parentsweb/parentsweb_reports.cfm?District=xxxxxxx&ReportType=Gradebook&sessionid=" .. alllsgr.sessionid .. "&ReportHash=" .. alllsgr.reporthash .. "&SchoolCode=xxxxxxx&StudentID=" .. alllsgr.studentid .. "&ClassID=" .. v.classid .. "&TermID=" .. v.termid, {
-- ACCEPT_ENCODING: "gzip"
-- COOKIE: "LB-Persist=" .. lbpersist
-- FOLLOWLOCATION: 1
-- }, gradeParse), v.classid .. "*" .. v.termid})
itgrade = #optionall
--hwths = {}
for i, v in pairs(hwcalurls)
handle = curl.easy(mytable)
mytable = {
URL: v[1]
ACCEPT_ENCODING: "gzip"
COOKIE: cookie
}
for i, v in pairs(mytable)
handle["setopt_" .. i\lower()](handle, v)
table.insert(optionall, mytable)
table.insert(asdasdasdasd, v[2])
-- table.insert(hwths, {canthread(thread_get, v[1], {
-- ACCEPT_ENCODING: "gzip"
-- COOKIE: cookie
-- }, homeworkCalendarParse), v[2]})
ithw = #optionall
--lessonplanths = {}
for i, v in pairs(lessonplanurls)
handle = curl.easy(mytable)
mytable = {
URL: v[1]
ACCEPT_ENCODING: "gzip"
COOKIE: cookie
}
for i, v in pairs(mytable)
handle["setopt_" .. i\lower()](handle, v)
table.insert(optionall, mytable)
table.insert(asdasdasdasd, v[2])
-- table.insert(lessonplanths, {canthread(thread_get, v[1], {
-- ACCEPT_ENCODING: "gzip"
-- COOKIE: cookie
-- }, lessonPlansParse), v[2]})
itlessonplan = #optionall
returnblob = url_util.curl_multi_read(optionall)
biginfo = {}
for i = 1, itgrade
blob = returnblob[i]
file_util.writefile("log/" .. asdasdasdasd[i], blob)
table.insert(biginfo, gradeParse(blob))
for i = itgrade + 1, ithw
blob = returnblob[i]
file_util.writefile("log/" .. asdasdasdasd[i], blob)
table.insert(biginfo, homeworkCalendarParse(blob))
for i = ithw + 1, itlessonplan
blob = returnblob[i]
file_util.writefile("log/" .. asdasdasdasd[i], blob)
table.insert(biginfo, lessonPlansParse(blob))
-- for i, v in pairs(gradeths)
-- info, blob = v[1]\join()
-- file_util.writefile("log/" .. v[2], blob)
-- table.insert(biginfo, info)
-- for i, v in pairs(hwths)
-- info, blob = v[1]\join()
-- file_util.writefile("log/" .. v[2], blob)
-- table.insert(biginfo, info)
-- for i, v in pairs(lessonplanths)
-- info, blob = v[1]\join()
-- file_util.writefile("log/" .. v[2], blob)
-- table.insert(biginfo, info)
file_util.writefile("watter.json", JSON\encode_pretty(biginfo))
url_util.curl_read_url("https://xxxxxxx.client.renweb.com/pw/?LogOut=1", { --gtfo
ACCEPT_ENCODING: "gzip"
COOKIE: cookie
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment