mooshak2api package

Submodules

mooshak2api.client module

class mooshak2api.client.Client(endpoint)[source]

Bases: object

A bundling of a mooshak2 endpoint, and a User. In most cases you should use mooshak2api.login rather than initiating this class yourself.

You should add a User to this Object manually, via using self.user. Included are default headers that should be used for most JSON based messages.

endpoint = None
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
headers_with_auth() → dict[source]

Returns common headers with the JWT Header included. Ensure that self.user is a User Object, and that the user has been logged in with the .login() method.

Returns:returns a dict containing headers
refresh()[source]

Refreshes this users token. Should be called every x seconds, in order to ensure that the user stays logged in

test()[source]

Tests the connection.rst to the server

Returns:returns True if a connection.rst could be made
user = None
mooshak2api.client.login(endpoint, username, password, contest=None, admin=False)[source]

Creates an authenticated client to interact with the Mooshak 2 API

Parameters:
  • endpoint – The API Endpoint, ending in a slash. E.g, https://mooshak2.dcc.fc.up.pt/mooshak-test/api/
  • username – A username for the connection.rst, E.g. admin
  • password – A password for the connection.rst, E.g. admin
  • contest – The contest for the (non admin) user to interact with
  • admin – If this is an admin account, and you want to administrate
Returns:

A Client Object

mooshak2api.contests module

class mooshak2api.contests.Contest[source]

Bases: mooshak2api.factory.GenericObject

A Mooshak2 Contest. The only required property that is required is an ID

create(connection)[source]

Creates a Contest

You should ensure that the contest has ID set, and that any properties that you want to add are in self.property_names :param connection: the Client to connect with :return: returns a request - with status 201 if successful

delete(connection)[source]

Deletes a Contest :param connection: the Client to connect with :return: returns a request - with status 201 if successful

update(connection)[source]

Updates a Contest :param connection: the Client to connect with :return: returns a request - with status 201 if successful

mooshak2api.contests.get(connection: mooshak2api.client.Client, contest_id: str) → mooshak2api.contests.Contest[source]

Gets a single Contest :param connection: Client to connect to :param contest_id: the ID of the contest. e.g. ToPAS14 :return: returns a Contest

mooshak2api.contests.get_all(connection: mooshak2api.client.Client) → Iterable[mooshak2api.contests.Contest][source]

mooshak2api.evaluation module

class mooshak2api.evaluation.Evaluation(contest_id, problem_id)[source]

Bases: mooshak2api.factory.GenericObject

notify_type
Returns the ‘notification type’ of the message, being one of:
  • success (Green)
  • warning (Amber/Orange)
  • error (Red)
  • info (blue)

This is based from self.status. If they is no status, then ‘none’ will be returned :return: str: notify_type

refresh(connection)[source]

Refreshes the data from the server :param connection: :return:

status = 'not_fetched'
type = 'evaluation_summary'

mooshak2api.factory module

class mooshak2api.factory.GenericObject[source]

Bases: object

as_json() → dict[source]

Returns the JSON representation of the object, based on the keys set in self.property_names :return:

create(connection)[source]
delete(connection)[source]
id = None
load_from_dict(json: dict)[source]

Reads data from a JSON Object/Dict, and sets the attributes of this object with each corresponding key

type
update(connection)[source]

mooshak2api.problems module

class mooshak2api.problems.Problem(contest_id)[source]

Bases: mooshak2api.factory.GenericObject

A problem of a Contest.
It must contain a Contest ID, as the REST API does not allow accessing problems directly
contest_id = None
delete(connection: mooshak2api.client.Client)[source]
evaluate(connection: mooshak2api.client.Client, problem_code)[source]
get_contest(connection: mooshak2api.client.Client)[source]
update(connection: mooshak2api.client.Client)[source]
mooshak2api.problems.get(connection: mooshak2api.client.Client, contest: Union[mooshak2api.contests.Contest, int], problem_id: int) → mooshak2api.problems.Problem[source]
mooshak2api.problems.get_all(connection: mooshak2api.client.Client, contest: Union[mooshak2api.contests.Contest, int]) → Iterable[mooshak2api.problems.Problem][source]

mooshak2api.user module

class mooshak2api.user.User(username, password, contest=None, admin=False)[source]

Bases: object

last_refresh = None
login(connection)[source]
token = None

Module contents

Mooshak2api - A Python API for interacting with the Mooshak 2 REST API