Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. var Magister = require('magister.js')
  2. var tools = require("./assets/tools.js");
  3.  
  4. /* Setting our settings. */
  5. var CONFIG_PATH = "config.json";
  6.  
  7. /* Load the config.json file. */
  8. var CONFIG = tools.loadJSONfile(CONFIG_PATH);
  9.  
  10. /* Check magister values. */
  11. if (CONFIG.Magister.url == "" || CONFIG.Magister.username == "" || CONFIG.Magister.password == "" ||
  12. typeof(CONFIG.Magister.url) != "string" || typeof(CONFIG.Magister.username) != "string" ||
  13. typeof(CONFIG.Magister.password) != "string") {
  14. tools.log("error", "CONFIG PARSE ERROR: Magister configuration is not filled in.");
  15. process.exit(1);
  16. }
  17.  
  18. function magisterLogin() {
  19. tools.log("info", "Trying to login to magister.")
  20.  
  21. new Magister.Magister({
  22.  
  23. school: {url: CONFIG.Magister.url},
  24. username: CONFIG.Magister.username,
  25. password: CONFIG.Magister.password
  26.  
  27. }).ready(function (err) {
  28.  
  29. printEndGrades(err, this)
  30. });
  31. }
  32.  
  33. /* ==========================
  34. * Functions and stuff below.
  35. * ========================== */
  36.  
  37. /* Print end grades to the console. (average grade)*/
  38. function printEndGrades(err, magisterlogin) {
  39. if (err) {
  40. tools.log("error", "Could not login to magister.", err);
  41. process.exit(1);
  42. }
  43.  
  44. // Log our succes!
  45. tools.log("info", "Logged into magister successfully.")
  46.  
  47. /* Get the current course */
  48. magisterlogin.currentCourse(function (err, currentCourse) {
  49. if (err) {
  50. tools.log("error", "Problem getting current course", err);
  51. process.exit(1);
  52. }
  53.  
  54. /* Get the grades inside of this course */
  55. currentCourse.grades(function (err, grades) {
  56. if (err) {
  57. tools.log("error", "Problem getting current course's grades", err);
  58. process.exit(1);
  59. }
  60.  
  61. /* Map the grades then log them */
  62. console.log(grades)
  63.  
  64. });
  65. });
  66. }
  67.  
  68. /* ==========================
  69. * Initialize
  70. * ========================== */
  71. magisterLogin();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement