Skip to content

Instantly share code, notes, and snippets.

@frederickfogerty
Created April 5, 2018 08:10
Show Gist options
  • Save frederickfogerty/1805c068bbe7b3f511d5246d7c725345 to your computer and use it in GitHub Desktop.
Save frederickfogerty/1805c068bbe7b3f511d5246d7c725345 to your computer and use it in GitHub Desktop.
Use Student Course Review API to upvote or downvote a review until it reaches the desired vote count
const vote = async ({id, direction}) => await fetch(
`http://www.studentcoursereview.co.nz/ajax/review_vote?id=${id}&direction=${direction}&_=1521348768004`
);
var voteTo = async ({ id, direction = "up", target }) => {
let currentScore = undefined;
while (true) {
const increment = currentScore == null ? 1 : Math.min(target - currentScore, 3);
const fetches = Array.from({length: increment}).map(() => vote({ id, direction }))
const results = await Promise.all(fetches);
const resultJsons = await Promise.all(results.map(res => res.json()))
currentScore = Math.max(...resultJsons.map(v => v.new_score));
if (
(direction == "up" && currentScore >= target) ||
(direction == "down" && currentScore <= target)
) {
console.log("The deed has been done");
return;
}
console.log(`Score is now ${currentScore}`);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment