From 180a94a1d0ddb96263a51f1e7e83286a1894a15e Mon Sep 17 00:00:00 2001 From: Prince2347X Date: Thu, 24 Jun 2021 10:36:09 +0530 Subject: [PATCH] Optimizations --- docs/source/conf.py | 5 +-- pydoodle/__init__.py | 4 ++- pydoodle/jdoodle.py | 73 ++++++++++++++++++++++++++++++++------------ 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 38b9e3f..6f651cf 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -13,13 +13,14 @@ import os import sys import re +import pydoodle import sphinx_rtd_theme import sphinx_rtd_dark_mode sys.path.insert(0, os.path.abspath('..')) +sys.path.append(os.path.abspath('.')) - -version = "v1.2.0" +version = "v1.1.2" # -- Project information ----------------------------------------------------- diff --git a/pydoodle/__init__.py b/pydoodle/__init__.py index 45d19aa..92285d2 100644 --- a/pydoodle/__init__.py +++ b/pydoodle/__init__.py @@ -1,10 +1,12 @@ from .jdoodle import Compiler +from .jdoodle import Output +from .errors import LimitExceeded, LinkNotSupported, LanguageNotSupported, UnauthorizedRequest, BadRequest ############ # METADATA # ############ -__version__ = "v1.2.0" +__version__ = "v1.1.2" __title__ = "pydoodle" __license__ = "MIT" __author__ = "Prince2347X" diff --git a/pydoodle/jdoodle.py b/pydoodle/jdoodle.py index e605bf8..a2c8346 100644 --- a/pydoodle/jdoodle.py +++ b/pydoodle/jdoodle.py @@ -1,30 +1,66 @@ +from typing import Any, Tuple + import requests from .errors import UnauthorizedRequest, BadRequest, LanguageNotSupported, LinkNotSupported, LimitExceeded class Output: - """ - The output of the executed script. - """ - def __init__(self, output, statusCode, memory, cpuTime): - self.output = output - self.statusCode = statusCode - self.memory = memory - self.cpuTime = cpuTime + def __init__(self, response_json: dict): + """ + The output of the executed script. + :param response_json: The response from the API + :type respose_json: dict + """ + self._output = response_json['output'], + self._statusCode = response_json['statusCode'], + self._memory = response_json['memory'], + self._cpuTime = response_json['cpuTime'] + + @property + def output(self) -> str: + """ + :returns: The output of the executed script. + :rtype: str + """ + return self.output + @property + def statusCode(self): + """ + :return: The status code of the API request. + :rtype: int + """ + return self._statusCode -class Compiler: - """ - Initialize the compiler which let you access the Jdoodle API. + @property + def memory(self) -> str: + """ + :return: Memory used to execute the script (in kilobytes). + :rtype: str + """ + return str(self._memory) + + @property + def cpuTime(self) -> str: + """ + :return: The time taken in the execution of the script (in seconds). + :rtype: str + """ + return self._cpuTime - :param clientId: The clientId which you can get from https://jdoodle.com/compiler-api/ - :type clientId: str - :param clientSecret: The clientSecret which you can get from https://jdoodle.com/compiler-api/ - :type clientSecret: str - """ + +class Compiler: def __init__(self, clientId: str, clientSecret: str): + """ + Initialize the compiler which let you access the Jdoodle API. + + :param clientId: The clientId which you can get from https://jdoodle.com/compiler-api/ + :type clientId: str + :param clientSecret: The clientSecret which you can get from https://jdoodle.com/compiler-api/ + :type clientSecret: str + """ if not isinstance(clientId, str): raise TypeError elif not isinstance(clientSecret, str): @@ -114,10 +150,7 @@ def execute(self, script: str, language: str, link: bool = False, stdIn: str = N response = requests.post(url=self.base_url, headers=self.headers, json=self.json) response_json = response.json() if response.status_code == 200: - return Output(output=response_json['output'], - statusCode=response_json['statusCode'], - memory=response_json['memory'], - cpuTime=response_json['cpuTime']) + return Output(response_json) else: error = response.json() if response.status_code == 401: