dtlib.py : ne crash pas si une image n'a pas de donnée exif

This commit is contained in:
Antoine Van Elstraete 2019-05-23 17:19:25 +02:00 committed by Antoine Van Elstraete
parent 557719baf6
commit 00270fdc18

View File

@ -6,28 +6,32 @@ from datetime import datetime
def extractor(dt_file, start, end): def extractor(dt_file, start, end):
catalog = {} catalog = {}
unknow_files = 0
conn = sqlite3.connect(dt_file) conn = sqlite3.connect(dt_file)
cursor = conn.cursor() cursor = conn.cursor()
req = "SELECT id, model, lens, exposure, aperture, iso, focal_length, datetime_taken, width, height FROM images;" req = "SELECT id, model, lens, exposure, aperture, iso, focal_length, datetime_taken, width, height FROM images;"
cursor.execute(req) cursor.execute(req)
res = cursor.fetchall() res = cursor.fetchall()
for data in res: for data in res:
img_date = datetime.strptime(data[7], "%Y:%m:%d %H:%M:%S") if not data[7]:
if start <= img_date <= end: unknow_files += 1
catalog.update({ else:
data[0]: img_date = datetime.strptime(data[7], "%Y:%m:%d %H:%M:%S")
{ if start <= img_date <= end:
'camera': data[1], catalog.update({
'lens': data[2], data[0]:
'shutter': float(data[3]*1000), {
'aperture': round(float(data[4]), 1), 'camera': data[1],
'iso': int(data[5]), 'lens': data[2],
'focal': float(data[6]), 'shutter': float(data[3]*1000),
'datetime': img_date, 'aperture': round(float(data[4]), 1),
'height': int(data[9]), 'iso': int(data[5]),
'width': int(data[8]) 'focal': float(data[6]),
} 'datetime': img_date,
}) 'height': int(data[9]),
'width': int(data[8])
}
})
cameras, lenses, focals, apertures, shutter_speeds = {}, {}, {}, {}, {} cameras, lenses, focals, apertures, shutter_speeds = {}, {}, {}, {}, {}
isos, dimensions, cameras_lenses, dates = {}, {}, {}, {} isos, dimensions, cameras_lenses, dates = {}, {}, {}, {}
cameras_list, lenses_list, focals_list, apertures_list, shutter_speeds_list = [], [], [], [], [] cameras_list, lenses_list, focals_list, apertures_list, shutter_speeds_list = [], [], [], [], []
@ -76,6 +80,7 @@ def extractor(dt_file, start, end):
dates.update({date: dates_list.count(date)}) dates.update({date: dates_list.count(date)})
return { return {
"total": len(catalog.keys()), "total": len(catalog.keys()),
"unknows": unknow_files,
"date": dates, "date": dates,
"cameras": cameras, "cameras": cameras,
"lenses": lenses, "lenses": lenses,