@@ -132,6 +132,8 @@ def _api_request(self, endpoint, http_method, **kwargs):
132132 response = requests .post (path , data = data , ** req_kw )
133133 else :
134134 response = requests .post (path , ** req_kw )
135+ elif http_method == 'PATCH' :
136+ response = requests .patch (path , data = data , ** req_kw )
135137 elif http_method == 'PUT' :
136138 response = requests .put (path , data = data , ** req_kw )
137139 elif http_method == 'DELETE' :
@@ -159,7 +161,7 @@ def _api_request(self, endpoint, http_method, **kwargs):
159161 return formatted_response
160162
161163 return response .json ()
162-
164+
163165 ###### JOB ENDPOINTS ######
164166
165167 def list_jobs (self ):
@@ -272,13 +274,6 @@ def _create_photo(self, payload=None):
272274 payload = payload
273275 )
274276
275- def calculate_md5 (self , file_path ):
276- md5_hash = hashlib .md5 ()
277- with open (file_path , "rb" ) as file :
278- for chunk in iter (lambda : file .read (4096 ), b"" ):
279- md5_hash .update (chunk )
280- return md5_hash .hexdigest ()
281-
282277 def upload_job_photo (self , photo_path , id ):
283278 return self ._upload_photo (photo_path , id , 'job' )
284279
@@ -320,7 +315,6 @@ def _upload_photo(self, photo_path, id, model='job'):
320315 photo_id = photo_resp ['id' ]
321316 res ['photo' ] = photo_resp
322317
323- # md5 = self.calculate_md5(photo_path)
324318 b64md5 = base64 .b64encode (bytes .fromhex (md5hash )).decode ('utf-8' )
325319 payload = {
326320 "use_cache_upload" : False ,
@@ -411,7 +405,7 @@ async def _download_bg_images(self, profile):
411405 temp_bgs .append (bg_image )
412406
413407 return temp_bgs if temp_bgs else None
414-
408+
415409 async def _download_image (self , image_url ):
416410 if not image_url .lower ().startswith ("http" ):
417411 raise Exception (f'Invalid retouchedUrl: "{ image_url } " - Please ensure the job is complete' )
@@ -451,7 +445,7 @@ async def _download_replaced_bg_image(self, file_name, input_image, output_path,
451445 async def download_all_photos (self , photos_list , profile , output_path ):
452446 if not os .path .exists (output_path ):
453447 raise Exception ("Invalid output path" )
454-
448+
455449 success_photos = []
456450 errored_photos = []
457451 bgs = []
@@ -461,7 +455,7 @@ async def download_all_photos(self, photos_list, profile, output_path):
461455 profile = self .get_profile (profile ['id' ])
462456 if profile ['photos' ]:
463457 bgs = await self ._download_bg_images (profile )
464-
458+
465459 photo_ids = [photo ["id" ] for photo in photos_list ]
466460 photo_options = {
467461 'bgs' : bgs
@@ -483,10 +477,10 @@ async def download_all_photos(self, photos_list, profile, output_path):
483477 return { 'success_photos' : success_photos , 'errored_photos' : errored_photos }
484478
485479 except Exception as e :
486- print (e )
480+ print ("Error has occurred whilst downloading photos:" , e )
487481
488482 return { 'success_photos' : success_photos , 'errored_photos' : errored_photos }
489-
483+
490484 async def download_photo (self , photo_id , output_path , profile = None , options = {}, semaphore = None ):
491485 if not os .path .exists (output_path ):
492486 raise Exception ("Invalid output path" )
@@ -496,7 +490,7 @@ async def download_photo(self, photo_id, output_path, profile = None, options =
496490 photo = self .get_photo (photo_id )
497491 profile_id = photo ['job' ]['profileId' ]
498492 file_name = photo ['name' ]
499-
493+
500494 try :
501495 if profile is None :
502496 profile = self .get_profile (profile_id )
0 commit comments