Code Monkey home page Code Monkey logo

magister-api-python's Introduction

Magister API

Summary:

This is a implementation for the Magister private API. You can(for now) use it to fetch a school roster and apitoken. This is done by using a headless selenium instance.


Setup:

You need to host this api on your own webserver, or you can run it on your own machine. It is not intended for heavy use, and it's not effective at all. The fetching takes around 30 second for the api key. You can use this key for a few hours.

Step 1: Clone the repository:

git clone https://github.com/maantjemol/magister-api-python
cd magister-api-python

Step 2: Create an environment and install requirements:

python3 -m venv venv
pip3 install -r requirements.txt

Step 3: Start server.py

python3 server.py

Usage:

You can make requests to http://localhost:5000. The currently implemented request are:

Authentication:

Base url: /api/auth

Parameter: Example:
username 234543
password weakPassword123
school ErasmusCollege

Example url: /api/auth?username=234543&password=weakPassword&school=ErasmusCollege
Response:

{
    "accessToken": "token"
}

NOTE: This request will take about 30 seconds

Rooster:

Base url: /api/rooster

Parameter: Example:
dateFrom 2020-09-25
dateTill 2020-10-02
school ErasmusCollege
apitoken API token you received in previous request

Example url: /api/rooster?dateFrom=2020-09-25&dateTill=2020-10-02&school=ErasmusCollege&apitoken=<token you received>
Response:

{
"Items": [
...

TODO:

  • Add auth page
  • Split roster and authentication
  • Add grades
  • Deploy it to a docker container
  • Add grades instructions
  • Add docker instructions
  • Add security
  • Make it cross platform

magister-api-python's People

Contributors

maantjemol avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

magister-api-python's Issues

Chrome binary cannot be found

I'm trying to (as a little side project) create a terminal application for magister that allows one to login and check their schedule and whatnot, but when testing this pretty cool looking project I came across the problem that somehow the chrome binary could not be found even though it should. Here's the output: (Where it says BINARY: /home/sjoerd/MagisTerm/magister-api-python/app/chromedriver its just something I quickly added for debugging. As you can see the path should be correct.)

sjoerd@penguin:~/MagisTerm/magister-api-python/app$ python3 server.py
 * Serving Flask app "server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 108-624-079
serving user
BINARY: /home/sjoerd/MagisTerm/magister-api-python/app/chromedriver
127.0.0.1 - - [14/Jun/2021 11:03:28] "GET /api/auth?username=22572&[email protected]&school=CSGdeWillemvanOranje HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/sjoerd/.local/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/sjoerd/MagisTerm/magister-api-python/app/server.py", line 23, in auth
    return jsonify(requests_magister.accesstoken(username, password, school))
  File "/home/sjoerd/MagisTerm/magister-api-python/app/requests_magister.py", line 9, in accesstoken
    accessToken = getApiToken(username, password, school)
  File "/home/sjoerd/MagisTerm/magister-api-python/app/apitoken.py", line 37, in getApiToken
    chrome_options=chrome_options, executable_path=chrome_driver)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/seleniumwire/webdriver/browser.py", line 86, in __init__
    super().__init__(*args, **kwargs)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/sjoerd/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
127.0.0.1 - - [14/Jun/2021 11:03:28] "GET /api/auth?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [14/Jun/2021 11:03:28] "GET /api/auth?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Jun/2021 11:03:29] "GET /api/auth?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Jun/2021 11:03:30] "GET /api/auth?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [14/Jun/2021 11:03:30] "GET /api/auth?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
127.0.0.1 - - [14/Jun/2021 11:03:30] "GET /api/auth?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
^Csjoerd@penguin:~/MagisTerm/magister-api-python/app$ ls /home/sjoerd/MagisTerm/magister-api-python/app/chromedriver
/home/sjoerd/MagisTerm/magister-api-python/app/chromedriver

I'd love to hear if you have any idea what goes wrong here.

PS: The chromedriver binary has executable permissions.

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.