Giter Club home page Giter Club logo

collegescheduler's Introduction

@cougargrades/collegescheduler

๐Ÿ“…๐Ÿ“ก Local reverse-proxy to UH CollegeScheduler API that can be re-authenticated automatically to consistently access up-to-date course schedules and catalog data.

https://uh.collegescheduler.com/ has a useful API for retrieving information about courses, however, it is only accessible during an active session made by digging through the MyUH portal. This project makes this API more accessible by sending background keepalive requests to make sessions last longer and refreshing login sessions behind the scenes to make the API more convenient to access for other applications.

It can even be run entirely in Docker.

Partial insight into the CollegeScheduler API and its endpoints has been written by au5ton over at: @au5ton/docs


screenshot

Webserver

Proxies unauthenticated requests to the local webserver to https://uh.collegescheduler.com/ with your cookie attached.

The webserver will automatically refresh the cookie with Puppet.js when the current one is expired, leaving no interruptions to API requests.

Note: Do not leave the local server exposed to the open internet because every unauthenticated client acts on your behalf.

Usage

Run inside Docker

This project is not on Docker Hub. To build from Github directly, follow these instructions.

  • Clone the github repo:

    git clone [email protected]:cougargrades/collegescheduler.git

  • cd collegescheduler

  • Build the docker image locally

    make build

    OR

    docker build . -t collegescheduler:dev

  • Create an .env file that is a copy of .env.example with your own information.

    MY_UH_PEOPLESOFT_ID=1234567
    MY_UH_PASSWORD=hunter2
    PROXY_SERVER_PORT=3003
    
  • Start a new container:

    docker run -i --env-file .env -p 3003:3003 collegescheduler:dev

Run as standalone

  • Prerequisite: Make sure Puppet.js functions as intended and has no errors before starting the proxy server. See guide below.
  • Install dependencies: npm install
  • Specify desired port in .env or with variable PROXY_SERVER_PORT.
  • Run server: npm run server

HTTP Responses

All HTTP responses that the proxy server makes are identical to those made to https://uh.collegescheduler.com/. However, there are some exceptions:

  • HTTP/511 Network Authentication Required:

    This means that you happened to catch the proxy server while it is in the middle of refreshing its cookie automatically. The refresh process takes about 10-13 seconds on a fast connection. After that period, your request will be serviceable while the backend is active on a new "session".

  • HTTP/502 Bad Gateway:

    This means that there was a back-end error proxying this request. The error message is included.

Puppet.js

puppet.js uses puppeteer to crawl my.uh.edu, portal to collegescheduler.com, and extract the cookies for use.

Usage

Note: Some environments will require troubleshooting with puppeteer. This project was designed with google-chrome-unstable=77.0.3833.0-1 in mind. Future releases may require updating the npm module puppeteer-core.

Command-line tool

  • With npm:

    • Install tool: npm install -g cougargrades/collegescheduler
    • Run tool: npx uhcs_puppet --help
  • Cloning directly:

    • git clone https://github.com/cougargrades/collegescheduler.git
    • cd collegescheduler/
    • Install dependencies: npm install
    • Run tool: ./src/puppet.js --help
  • Copy example file: cp .env.example .env

  • Edit .env file with login details

    • Or:
    • Specify the environment variables in your shell:
    • $ MY_UH_PEOPLESOFT_ID=1234567
    • $ MY_UH_PASSWORD=hunter2
  • Follow instructions on running in the --help page.

    $ ./src/puppet.js -o cookiejar.json
    
    [๐Ÿ’ฌ] Login https://my.uh.edu ...
    [โœ…] Logged in!
    [๐Ÿ’ฌ] Portalling (Student Center -> Schedule Planner) ...
    [๐Ÿ“] Extracting cookies https://uh.collegescheduler.com ...
    [โœ…] API access confirmed
    [๐Ÿช] CookieJar written to cookiejar.json
    
    $ cat cookiejar.json
    {
    "version": "[email protected]",
    ...
    "cookies": [
    {
    "key": "__RequestVerificationToken",
    "value": "...",
        ...
    },
    {
    "key": ".AspNet.Cookies",
    "value": "...",
    ...
    }
    ]
    }
    

Node module

  • Developed with Node 10. Must support ES7 async/await and maybe other features.

  • Install dependency: npm install cougargrades/collegescheduler

  • Sample code:

    const { Puppet } = require('@cougargrades/collegescheduler')
    
    let options = {
        logging: true, // [true | false]
        format: 'set-cookie' // ['jar' | 'set-cookie']
    }
    
    let cookie = await Puppet.extract('177554', 'secretpassword', options)
    
    console.log(cookie) // '__RequestVerificationToken=abcdef; AspNet.Cookies=uvwxyz'

Reference:

collegescheduler's People

Contributors

au5ton avatar dependabot[bot] avatar imgbotapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.