-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_utils.py
38 lines (29 loc) · 930 Bytes
/
image_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
import pathlib
import os.path
import requests
IMAGE_FOLDER = 'images'
logging.basicConfig(
format='%(levelname)-8s [%(asctime)s] %(message)s',
level=logging.DEBUG,
filename='log.log'
)
def get_image(url, api_name, filename):
pathlib.Path(
os.path.join(IMAGE_FOLDER, api_name)
).mkdir(parents=True, exist_ok=True)
response = requests.get(url)
logging.info(f'Getting image: {os.path.join(IMAGE_FOLDER, api_name, filename)}')
with open(os.path.join(IMAGE_FOLDER, api_name, filename), 'wb') as file:
file.write(response.content)
def get_list_of_images():
images = []
for root, subs, files in os.walk(IMAGE_FOLDER):
for file in files:
images.append(os.path.join(root, file))
for folder in subs[:]:
if folder.startswith('.'):
subs.remove(folder)
return images
if __name__ == '__main__':
pass