Skip to content

Instantly share code, notes, and snippets.

@iarigby
Last active September 12, 2022 03:52
Show Gist options
  • Save iarigby/424e799eced56a377ffa8829a71de866 to your computer and use it in GitHub Desktop.
Save iarigby/424e799eced56a377ffa8829a71de866 to your computer and use it in GitHub Desktop.
Download all assignments from google classroom (student work window)
/**
HOW TO USE
1. go to assignment submissions (classwork > click assignment > student work)
2. open developer console ( F12 or right click > inspect element > console in top)
3. copy and paste this code, assignments will be downloaded in 5 second intervals
NOTE: CHANGE auth_user IF NECESSARY
if you are signed in to multiple google accounts, you need to select whichever you use for classroom
(ie freeuni account). If that account is the default one, leave at 0. Otherwise, sign in to gmail with that account
and the number will be displayed in url bar (https://mail.google.com/mail/u/$number), enter that
NOTE files will be downloaded to default download location (~/Downloads)
move all zips/rars from there before launching the script, afterwards you can easily select
newly downloaded files and move elsewhere
*/
const auth_user=2
// these ids work on paradigms, methodologies
const studentDiv = "WkZsyc"
const downloadDiv = "maXJsd"
const turnedInDiv = "vzcr8"
const INTERVAL = 5000
function downloadAssignments() {
getAssignments()
.filter(currentGroup)
.map(getAssignmentLink)
.filter(e => e != null) // submitted assignments that don't have attachment, how tf but it happened
.map(extractId)
.map(createDownloadLink)
.map(downloadAtInterval)
}
function getAssignments() {
return Array.from(document.getElementsByClassName(studentDiv))
.filter(e => {
const turned_in_status = Array.from(e.getElementsByClassName(turnedInDiv))
return turned_in_status.length > 0 && turned_in_status[0].innerHTML.includes("Turned in")
})
}
function getAssignmentLink(elem) {
const linkElement = Array.from(elem.getElementsByClassName(downloadDiv))[1]
return linkElement ? linkElement.href : null
}
function extractId(driveUrl) {
const rx = /https:\/\/drive.google.com\/open\?id=(.*)&authuser=?/
const res = rx.exec(driveUrl)
return res[1]
}
function createDownloadLink(id) {
return `https://drive.google.com/a/freeuni.edu.ge/uc?authuser=${auth_user}&id=${id}&export=download`
}
function downloadAtInterval(url, index) {
setTimeout(function() {
console.log(`downloading assignment ${index}`)
window.open(url)
}, index*INTERVAL);
}
function currentGroup(elem) {
// TODO
return true
// todo filter empty
// todo use comma delimeter
const list = studentList.split("\n")
const nameElem = elem.getElementsByClassName("J33wTc")
const name = Array.from(nameElem)[0].innerHTML.toLowerCase()
console.log(name)
let result = list.find(email => isName(email, name, 0, 1))
if (! result)
result = list.find(email => isName(email, name, 1, 0))
return result
}
function isName(email, name, nameIndex, surnameIndex) {
const arr = name.split(" ")
if (arr.length < 2) return false
const firstname = arr[nameIndex]
const surname = arr[surnameIndex]
const surnamePrefix = email => email.includes(surname.substr(0,3))
return email[0] == firstname[0] && surnamePrefix(email)
}
downloadAssignments()
@arielsantosllanita
Copy link

Annotation 2021-02-16 124159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment