-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckimages.py
More file actions
36 lines (26 loc) · 799 Bytes
/
checkimages.py
File metadata and controls
36 lines (26 loc) · 799 Bytes
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
#!/usr/bin/env python3
"""
Description: Check if all the images are present.
Author: P. Sempere (sempere.dev)
"""
from glob import glob
from json import load
from os.path import exists
errors = 0
filenames = set()
with open('data.json') as fp:
for obj in load(fp):
filename = 'media/' + obj['image']
filenames.add(filename)
if not exists(filename):
print(f'Image not found: {obj["image"]} [{obj["name"]} - {obj["family"]} - {obj["discoverer"]}]')
errors += 1
for image in glob('media/**', recursive=True):
if '.' in image and image not in filenames:
print(f'Image {image} is not used')
errors += 1
if errors:
print(f'Finished with {errors} errors!')
exit(1)
else:
print('All images checked successfuly!')