Skip to content

Automatically registers you on Minerva with Puppeteer and GCP

License

Notifications You must be signed in to change notification settings

ding-ma/mcgill-autoregistration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

McGill Minerva Automatic register

The goal of this project is to use a cloud service like AWS or GCP and create a cron job in order to run them at specific intervals

The script first webscrapes VSB to determine if there is a place available in the class, then it will proceed to register. If you think that I'm stealing your credentials for minerva, just go look at the source code, it is 148 lines.

WARNING: This program is to be used with people with knowledge with cloud infrastructure and node.js. I tried my best to make the instructions clear but anyone with any prior knowledge should be able to figure things out. Contact me if you need help!

To run

  1. rename sample.env to .env
  2. rename sample.env.yml to .env.yml
  3. fill out both .env file. The yml file is used for google cloud function whereas the regular one is for local

DO NOT touch the package.json in the src folder as they are used for deploying through the CLI.

How to use locally

  1. Go on VSB and copy the URL after you have chosen your classes.
  2. Modify the content of config JSON in src/function.js to match yours.
  3. The CRN is a list of all CRN of the class you would like to register. Those can be found on VSB also.
  4. To run, simply write npm install then npm start from the root of this project in your command line.

How to host on a Google Cloud Service

Available function name:

  • closedSection for closed section class
  • multiclass for multiclass registration on one function
  • waitlist for a waitlist class
  • waitlistNotify for receving an email when wait list has a new empty seat

Readme in src folder has more detailed information

Through CLI

Assuming you have a project and already logged in. During this process, it ask you to enable some API, simply hit yes. To deploy a function, simply run

gcloud functions deploy FUNCTION_NAME --source=src/FOLDER --trigger-http --allow-unauthenticated --env-vars-file=.env.yml --runtime=nodejs14 --memory=512MB

Give it a function name and make sure to mark the correct source folder for the script you want to deploy. This will return a httpsTrigger url and you can use that in cloud scheduler.

gcloud scheduler jobs create http NAME --schedule "* * * * 15" --uri=HTTPURL --http-method GET

Give the cloud scheduler a NAME, make sure to change the schedule and the uri. It is currently set for every 15 min. You can use crontab guru to customize it. The more frequent you run it, the higher your bill will be. Feel free to customize the rest of the fields to your liking, but those are the basics to run the project on GCP.

Through GUI (not recommended)

  1. Create a Cloud Function with content of src/SCRIPT_YOU_WANT/function.js. Use HTTP Trigger, 512mb of ram, function to execute is the export.FUNCTIONNAME, allow unauthorized requests (makes life easier).
  2. Modify the config json variable as needed in the script.
  3. Use the following package.json for GCP since the npm start is slightly different from the one located at the root of the project.
{
  "name": "mcgill-autoregistration",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "index.(your_chosen_function)"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "puppeteer": "^2.1.1",
    "@sendgrid/mail": "^6.5.5",
    "dotenv": "^8.2.0",
  }
}
  1. Once deployed, create Cloud Scheduler that calls the url generated by the function with a GET request. Choose an appropriate frequency (The more you run the function, the higher the costs!)
    4.1 I'm running mine every 30mins or so, if you would like to customize the time use this amazing tool

To use SendGrid

If you do not want to have email notifications, set "wantEmail": false in config.wantEmail.
To receive emails follow these steps:

  1. Sign up on sendgrid.
  2. Copy down the API key and use it in the program.
  3. Write your email on line 110 of function.js.

A free trial should be more than enough for our purposes as we get 100 free emails a day.

Documentation of .env

Below, all the fields of the config JSON are described

  • email: McGill Minerva username
  • password: McGill Minerva password
  • term: Term you wish to register for, found in VSB URL (ex. term=202005)
  • CRN: List of CRNs you wish to register for, found in VSB at bottom of screen
  • url: Select the classes you want on VSB for your selected term then copy the URL over
  • wantEmail: Set to true if you want an email notification upon successful registration
  • notifEmail: Where to send notification email to, leave as "" if wantEmail is false
  • sgApiKey: Received when registered for sendgrid, leave as "" if wantEmail is false

Couple notes:

  • There is a MAXIMUM of 10 CRN that you can have, those included the tutorial's CRN.
  • Each CRN must be comma separated with NO SPACE
  • The semesterfield needs to follow this pattern: YYYYMM
  • YYYY represents the academic year
  • MM is the semester where Fall is 09, Winter is 01, Summer is 05.
    For example, if I want to register for fall 2020, I would write 202009.
  • The script checks on vsb first to see if there are spots in the class. If so, it will proceed to register on Minerva. This is to prevent using all the registration limit which is around 1000 per semester.
  • To run on the cloud, we need to use the headless version of chrome headless: true, if you want to see the browser, simply set to headless: false in function.js.
  • You can have conflicting classes schedule in VSB, the program will still work like this: image
    You will need to find the CRN of them separately because VSB will not generate a schedule for you.

Exmaple of Config

Currently I want to register to all the classes shown in the image for the summer term, my config variable will look like this:

const config = {
    "regEmail": "[email protected]",
    "password": "password",
    "term": "202005",
    "CRN": "527,528,491,850,285,288,289",
    "url": "https://vsb.mcgill.ca/vsb...",
    "wantEmail": true,
    "notifEmail": "",
    "sgApiKey": "SG.xxx..."
};

Notice how CRN 527 (lecture) and 528 (tutorial) for FACC300 is inputted.

Upcoming features and todos

  • Ping VSB, and check if the class is free. If yes, proceed to register.
  • Log files generated by local script.
  • Make code more modular (Help needed!).
  • Determine the update frequency on VSB

Feature request

Create an issue and we will talk about it!

About

Automatically registers you on Minerva with Puppeteer and GCP

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •