Skip to content

Commit 764854e

Browse files
authored
Merge pull request #7 from skylab-tech/SCP-4-v2-touchups
Scp 4 v2 touchups
2 parents dc406c7 + 1606657 commit 764854e

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ If upload fails, the photo object is deleted for you. If upload succeeds and you
203203

204204
This function handles downloading the output photos to a specified directory.
205205

206-
```dotnet
206+
```python
207207
photos_list = completed_job.photos;
208208

209209
download_results = await api.download_all_photos(photos_list, completed_job.profile, "/output/folder/path");
@@ -216,7 +216,7 @@ Output:
216216

217217
OR
218218

219-
```dotnet
219+
```python
220220
api.download_photo(photo_id, "/output/folder/path");
221221
```
222222

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ aiohttp>=3.9.3
22
pylint>=1.8.3
33
pytest-cov>=2.6.1
44
pytest>=3.0.5
5-
pyvips>=2.2.2
5+
pyvips>=2.0.2
66
requests>=2.0.0
77
requests_mock>=1.5.2
88
decouple>=0.0.7

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name='skylab_studio',
14-
version='0.0.11',
14+
version='0.0.12',
1515
author='skylabtech',
1616
author_email='[email protected]',
1717
packages=find_packages(),

skylab_studio/studio_client.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

skylab_studio/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
For more information, visit https://studio.skylabtech.ai
44
"""
55

6-
VERSION = '0.0.11'
6+
VERSION = '0.0.12'

test/test_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_update_job(api):
7676
'name': new_job_name
7777
}
7878
result = api.update_job(job_id, payload=payload)
79-
assert result is not None
79+
assert result['name'] == new_job_name
8080

8181
def test_cancel_job(api):
8282
job_name = str(uuid.uuid4())
@@ -148,11 +148,13 @@ def test_get_profile(api):
148148

149149
def test_update_profile(api):
150150
global profile_id
151+
new_profile_name = str(uuid.uuid4())
151152
payload = {
153+
'name': new_profile_name,
152154
'description': 'a description!'
153155
}
154156
result = api.update_profile(profile_id, payload=payload)
155-
assert result is not None
157+
assert result['name'] == new_profile_name
156158

157159
def test_get_photo(api):
158160
global photo_id

0 commit comments

Comments
 (0)