Skip to content

Instantly share code, notes, and snippets.

@adammw
Created September 12, 2016 16:05
Show Gist options
  • Save adammw/e64129be639312a2d38eccd6c7fb591d to your computer and use it in GitHub Desktop.
Save adammw/e64129be639312a2d38eccd6c7fb591d to your computer and use it in GitHub Desktop.
// Simple script to extract raw grade data from turnitin
// Replace the variables below and execute in a JS console on api.turnitin.com
var API_BASE = 'https://api.turnitin.com/';
var sessionId = 'REPLACE_ME';
var assignmentId = 'REPLACE_ME';
var rubricCriterion = {};
fetch(`${API_BASE}/assignment/${assignmentId}?&lang=en_us&output=json&session-id=${sessionId}`)
.then((resp) => { return resp.ok && resp.json() })
.then((assignmentData) => {
var assignment = assignmentData.Assignment[0];
return fetch(`${API_BASE}/gm3/rubric/${assignment.rubric}?cv=1&cid=${assignment.class}&assignment_id=${assignmentId}&lang=en_us&output=json&session-id=${sessionId}`)
})
.then((resp) => { return resp.ok && resp.json() })
.then((rubricData) => {
rubricCriterion = rubricData.RubricCriterion;
})
.then(() => {
return fetch(`${API_BASE}/assignment/${assignmentId}/papers?cv=1&lang=en_us&output=json&session-id=${sessionId}`)
})
.then((resp) => { return resp.ok && resp.json() })
.then((papersData) => {
return Promise.all(papersData.PaperStub.map((paper) => {
return fetch(`${API_BASE}/paper/${paper.id}/grade_mark?cv=1&lang=en_us&output=json&session-id=${sessionId}`)
.then((resp) => { return resp.ok && resp.json() })
.then((gradeData) => {
var scores = rubricCriterion.map((criterion) => {
var feedback = gradeData.RubricScoringFeedback && gradeData.RubricScoringFeedback.find((feedback) => feedback.criterion == criterion.id)
return feedback && feedback.score;
})
return [paper.author_full_name, ...scores, gradeData.Read[0].last_saved];
})
}))
})
.then((paperGradesData) => {
var header = ['Author Name'];
rubricCriterion.forEach((criterion) => { header.push(criterion.name) })
header.push('Last Saved');
paperGradesData.unshift(header);
return paperGradesData.map((d) => d.join(', ')).join('\n')
})
.then(console.log.bind(console));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment