mooshak2api package¶
Submodules¶
mooshak2api.client module¶
-
class
mooshak2api.client.Client(endpoint)[source]¶ Bases:
objectA 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.GenericObjectA 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
-
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
-
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:
-
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¶
-
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¶
mooshak2api.user module¶
Module contents¶
Mooshak2api - A Python API for interacting with the Mooshak 2 REST API