Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Magister = require('magister.js')
- var tools = require("./assets/tools.js");
- /* Setting our settings. */
- var CONFIG_PATH = "config.json";
- /* Load the config.json file. */
- var CONFIG = tools.loadJSONfile(CONFIG_PATH);
- /* Check magister values. */
- if (CONFIG.Magister.url == "" || CONFIG.Magister.username == "" || CONFIG.Magister.password == "" ||
- typeof(CONFIG.Magister.url) != "string" || typeof(CONFIG.Magister.username) != "string" ||
- typeof(CONFIG.Magister.password) != "string") {
- tools.log("error", "CONFIG PARSE ERROR: Magister configuration is not filled in.");
- process.exit(1);
- }
- function magisterLogin() {
- tools.log("info", "Trying to login to magister.")
- new Magister.Magister({
- school: {url: CONFIG.Magister.url},
- username: CONFIG.Magister.username,
- password: CONFIG.Magister.password
- }).ready(function (err) {
- printEndGrades(err, this)
- });
- }
- /* ==========================
- * Functions and stuff below.
- * ========================== */
- /* Print end grades to the console. (average grade)*/
- function printEndGrades(err, magisterlogin) {
- if (err) {
- tools.log("error", "Could not login to magister.", err);
- process.exit(1);
- }
- // Log our succes!
- tools.log("info", "Logged into magister successfully.")
- /* Get the current course */
- magisterlogin.currentCourse(function (err, currentCourse) {
- if (err) {
- tools.log("error", "Problem getting current course", err);
- process.exit(1);
- }
- /* Get the grades inside of this course */
- currentCourse.grades(function (err, grades) {
- if (err) {
- tools.log("error", "Problem getting current course's grades", err);
- process.exit(1);
- }
- /* Map the grades then log them */
- console.log(grades)
- });
- });
- }
- /* ==========================
- * Initialize
- * ========================== */
- magisterLogin();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement