From e7bfb3b3793fc614f91384725f336c061601e15d Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 22 Jun 2022 11:20:34 +0200 Subject: [PATCH] Some changes --- classes/adonis.py | 33 +++++++++++++++++++++++++-------- classes/config.py | 6 +++++- worker.py => pindata.py | 3 ++- 3 files changed, 32 insertions(+), 10 deletions(-) rename worker.py => pindata.py (94%) diff --git a/classes/adonis.py b/classes/adonis.py index fd03395..d801866 100644 --- a/classes/adonis.py +++ b/classes/adonis.py @@ -11,18 +11,24 @@ from const import USER_AGENT from PIL.Image import Image +CREW_PORTAL = 0 +INTEGRATION = 1 + + class Adonis: - def __init__(self, crew_portal_base_url: str, login: str, password: str): + def __init__(self, crew_portal_base_url: str, integration_base_url: str, login: str, password: str): self.crew_portal_base_url = crew_portal_base_url + self.integration_base_url = integration_base_url self.login = login self.password = password @classmethod def fromConfig(cls, config): - return cls(config.crew_portal_base_url, config.login, config.password) + return cls(config.crew_portal_base_url, config.integration_base_url, config.login, config.password) - def requestCrewPortal(self, endpoint: str, payload: dict, add_token: bool = True, wrap_request: bool = True, extract_response: bool = True): - url = urljoin(self.crew_portal_base_url, endpoint) + def request(self, endpoint: str, payload: dict, add_token: bool = True, wrap_request: bool = True, extract_response: bool = True, api: int = CREW_PORTAL): + base_url = self.crew_portal_base_url if api == CREW_PORTAL else self.integration_base_url + url = urljoin(base_url, endpoint) req = Request(url) req.add_header("User-Agent", USER_AGENT) @@ -30,7 +36,7 @@ class Adonis: req.add_header("Accept", "application/json") if add_token: - payload["Authentication_Token"] = self.getTokenCrewPortal() + payload["Authentication_Token"] = self.getToken(api=api) if wrap_request: payload = {"request": payload} @@ -51,7 +57,14 @@ class Adonis: return res - def getTokenCrewPortal(self, lifetime: int = 60): + + def requestIntegration(self, endpoint: str, payload: dict, add_token: bool = True, wrap_request: bool = True, extract_response: bool = True): + return self.request(endpoint, payload, add_token, wrap_request, extract_response, INTEGRATION) + + def requestCrewPortal(self, endpoint: str, payload: dict, add_token: bool = True, wrap_request: bool = True, extract_response: bool = True): + return self.request(endpoint, payload, add_token, wrap_request, extract_response, CREW_PORTAL) + + def getToken(self, lifetime: int = 60, api: int = CREW_PORTAL): data = { "credentials": { "Login": self.login, @@ -60,7 +73,8 @@ class Adonis: } } - result = self.requestCrewPortal("GNL_API_AUTHENTICATION", data, False, False) + method = self.requestCrewPortal if api == CREW_PORTAL else self.requestIntegration + result = method("GNL_API_AUTHENTICATION", data, False, False) return result["Authentication_Token"] @@ -94,4 +108,7 @@ class Adonis: if profile_picture: crew._profile_picture = self.getCrewProfilePicture(pin) - return crew \ No newline at end of file + return crew + + def getRequirements(): + pass diff --git a/classes/config.py b/classes/config.py index 2924d60..4d1c9ce 100644 --- a/classes/config.py +++ b/classes/config.py @@ -9,10 +9,14 @@ class Config: def crew_portal_base_url(self): return self.config["ADONIS"]["CrewPortalBaseURL"] + @property + def integration_base_url(self): + return self.config["ADONIS"]["IntegrationBaseURL"] + @property def login(self): return self.config["ADONIS"]["Login"] @property def password(self): - return self.config["ADONIS"]["Password"] \ No newline at end of file + return self.config["ADONIS"]["Password"] diff --git a/worker.py b/pindata.py similarity index 94% rename from worker.py rename to pindata.py index 9f0e02b..dcea934 100644 --- a/worker.py +++ b/pindata.py @@ -1,4 +1,5 @@ from argparse import ArgumentParser +from json import dumps from classes.config import Config from classes.adonis import Adonis @@ -28,4 +29,4 @@ if __name__ == "__main__": data[pin] = crewdata - print(data) \ No newline at end of file + print(dumps(data))