From 67c06af2a801762fe2b32494f1bd767d1df34fa8 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 8 Apr 2022 11:45:05 +0200 Subject: [PATCH] Add license, retrieve crew profile picture --- LICENSE | 21 +++++++++++++++++++++ classes/adonis.py | 27 ++++++++++++++++++++++++--- classes/crew.py | 7 ++++++- const.py | 2 +- requirements.txt | 1 + worker.py | 1 + 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2a1fbe3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Kumi Systems e.U. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/classes/adonis.py b/classes/adonis.py index c9c70e3..fd03395 100644 --- a/classes/adonis.py +++ b/classes/adonis.py @@ -1,4 +1,5 @@ from urllib.request import urlopen, Request, urljoin +from base64 import b64decode import json @@ -7,6 +8,8 @@ from classes.crew import Crew from const import USER_AGENT +from PIL.Image import Image + class Adonis: def __init__(self, crew_portal_base_url: str, login: str, password: str): @@ -27,7 +30,7 @@ class Adonis: req.add_header("Accept", "application/json") if add_token: - payload["Authentication_Token"] = self.getToken() + payload["Authentication_Token"] = self.getTokenCrewPortal() if wrap_request: payload = {"request": payload} @@ -70,7 +73,25 @@ class Adonis: return result - def getCrew(self, pin): + def getCrewProfilePicture(self, pin): + data = { + "Pin": pin + } + + result = self.requestCrewPortal("DG_ProfilePictureRead", data) + + try: + return result["FileBase64"] + except AdonisError: + return None + + def getCrew(self, pin, personal_data=True, profile_picture=True): crew = Crew(pin) - crew._personal_data = self.getCrewPersonalData(pin) + + if personal_data: + crew._personal_data = self.getCrewPersonalData(pin) + + if profile_picture: + crew._profile_picture = self.getCrewProfilePicture(pin) + return crew \ No newline at end of file diff --git a/classes/crew.py b/classes/crew.py index c892542..5fd0909 100644 --- a/classes/crew.py +++ b/classes/crew.py @@ -2,6 +2,7 @@ class Crew: def __init__(self, pin): self.pin = pin self._personal_data = None + self._profile_picture = None @property def firstName(self): @@ -17,4 +18,8 @@ class Crew: @property def birthDate(self): - return self._personal_data["DetailsAll"]["Details"]["BirthDate"] \ No newline at end of file + return self._personal_data["DetailsAll"]["Details"]["BirthDate"] + + @property + def profilePicture(self): + return self._profile_picture \ No newline at end of file diff --git a/const.py b/const.py index a8fc4cb..bb7f04b 100644 --- a/const.py +++ b/const.py @@ -1 +1 @@ -USER_AGENT = "PyAdonis / dev (https://kumi.systems)" \ No newline at end of file +USER_AGENT = "PyAdonis/dev (https://kumi.systems)" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e69de29..037103e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +pillow \ No newline at end of file diff --git a/worker.py b/worker.py index 756ed53..9f0e02b 100644 --- a/worker.py +++ b/worker.py @@ -24,6 +24,7 @@ if __name__ == "__main__": crewdata["lastName"] = crew.lastName crewdata["dob"] = crew.birthDate crewdata["password"] = crew.birthDate.replace("-","") + crewdata["profilePicture"] = crew.profilePicture data[pin] = crewdata