Compare commits

...

2 Commits

2 changed files with 81 additions and 23 deletions

View File

@ -26,15 +26,30 @@ def get_exif(img_raw, exif_data):
if v == "Software":
exif_data['Software'] = exifdata[k]
if v == "DateTime":
exif_data['DateTime'] = datetime.strptime(exifdata[k], date_format)
exif_data['DateTime'] = datetime.strptime(
exifdata[k],
date_format,
)
if v == "DateTimeOriginal":
exif_data['DateTimeOriginal'] = datetime.strptime(exifdata[k], date_format)
exif_data['DateTimeOriginal'] = datetime.strptime(
exifdata[k],
date_format,
)
if v == "DateTimeDigitized":
exif_data['DateTimeDigitized'] = datetime.strptime(exifdata[k], date_format)
exif_data['DateTimeDigitized'] = datetime.strptime(
exifdata[k],
date_format,
)
if v == "FNumber":
exif_data['fnumber'] = round(exifdata[k][0] / exifdata[k][1], 1)
exif_data['fnumber'] = round(
exifdata[k][0] / exifdata[k][1],
1,
)
if v == "DigitalZoomRatio":
exif_data['DigitalZoomRatio'] = round(exifdata[k][0] / exifdata[k][1], 2)
exif_data['DigitalZoomRatio'] = round(
exifdata[k][0] / exifdata[k][1],
2,
)
if v == "TimeZoneOffset":
exif_data['TimeZoneOffset'] = exifdata[k]
if v == "GPSInfo":
@ -42,28 +57,46 @@ def get_exif(img_raw, exif_data):
for h, i in GPSTAGS.items():
if h in exifdata[k]:
if i == 'GPSAltitudeRef':
gpsinfo['GPSAltitudeRef'] = int.from_bytes(exifdata[k][h], "big")
gpsinfo['GPSAltitudeRef'] = int.from_bytes(
exifdata[k][h],
"big",
)
if i == 'GPSAltitude':
gpsinfo['GPSAltitude'] = round(exifdata[k][h][0] / exifdata[k][h][1], 3)
gpsinfo['GPSAltitude'] = round(
exifdata[k][h][0] / exifdata[k][h][1],
3,
)
if i == 'GPSLatitudeRef':
gpsinfo['GPSLatitudeRef'] = exifdata[k][h]
if i == 'GPSLatitude':
gpsinfo['GPSLatitude'] = calc_coordinate(exifdata[k][h])
gpsinfo['GPSLatitude'] = calc_coordinate(
exifdata[k][h],
)
if i == 'GPSLongitudeRef':
gpsinfo['GPSLongitudeRef'] = exifdata[k][h]
if i == 'GPSLongitude':
gpsinfo['GPSLongitude'] = calc_coordinate(exifdata[k][h])
gpsinfo['GPSLongitude'] = calc_coordinate(
exifdata[k][h],
)
update_gpsinfo(gpsinfo, exif_data)
def update_gpsinfo(gpsinfo, exif_data):
if 'GPSAltitudeRef' in gpsinfo and 'GPSLatitude' in gpsinfo:
exif_data['GPSAltitude'] = gpsinfo['GPSAltitude']
exif_data['GPSAboveSeaLevel'] = False if gpsinfo['GPSAltitudeRef'] != 0 else True
exif_data['GPSAboveSeaLevel'] = False
if gpsinfo['GPSAltitudeRef'] == 0:
exif_data['GPSAboveSeaLevel'] = True
if 'GPSLatitudeRef' in gpsinfo and 'GPSLatitude' in gpsinfo:
exif_data['GPSLatitude'] = gpsinfo['GPSLatitude'] if gpsinfo['GPSLatitudeRef'] != 'S' else 0 - gpsinfo['GPSLatitude']
if gpsinfo['GPSLatitudeRef'] != 'S':
exif_data['GPSLatitude'] = gpsinfo['GPSLatitude']
else:
exif_data['GPSLatitude'] = 0 - gpsinfo['GPSLatitude']
if 'GPSLongitudeRef' in gpsinfo and 'GPSLongitude' in gpsinfo:
exif_data['GPSLongitude'] = gpsinfo['GPSLongitude'] if gpsinfo['GPSLongitudeRef'] != 'W' else 0 - gpsinfo['GPSLongitude']
if gpsinfo['GPSLongitudeRef'] != 'W':
exif_data['GPSLongitude'] = gpsinfo['GPSLongitude']
else:
exif_data['GPSLongitude'] = 0 - gpsinfo['GPSLongitude']
def calc_coordinate(x):

View File

@ -10,6 +10,28 @@ from .get_exif_data import get_exif_data
def process_uploaded_photo(filename, current_user, app_config):
crop_photo(filename, app_config['PHOTO_SAVE_PATH'])
exif_data = get_exif_data(filename)
if 'DateTimeOriginal' in exif_data:
my_date_time_original = exif_data['DateTimeOriginal']
else:
my_date_time_original = None
if 'DateTimeDigitized' in exif_data:
my_date_time_digitized = exif_data['DateTimeDigitized']
else:
my_date_time_digitized = None
if 'DigitalZoomRatio' in exif_data:
my_digital_zoom_ratio = exif_data['DigitalZoomRatio']
else:
my_digital_zoom_ratio = None
if 'TimeZoneOffset' in exif_data:
my_timezone_offset = exif_data['TimeZoneOffset']
else:
my_timezone_offset = None
if 'GPSAboveSeaLevel' in exif_data:
my_gps_above_sealevel = exif_data['GPSAboveSeaLevel']
else:
my_gps_above_sealevel = None
conn = psycopg2.connect(
dbname=app_config['DATABASE_NAME'],
user=app_config['DATABASE_USER'],
@ -19,7 +41,10 @@ def process_uploaded_photo(filename, current_user, app_config):
cur = conn.cursor()
cur.execute("SELECT setval('photo_id_seq', (SELECT MAX(id) FROM photo))")
conn.commit()
cur.execute("SELECT count(id) FROM photo WHERE photo_name=%s", (filename, ))
cur.execute(
"SELECT count(id) FROM photo WHERE photo_name=%s",
(filename, ),
)
if cur.fetchone()[0] == 0:
sql_statement = "INSERT INTO photo("
@ -84,14 +109,14 @@ def process_uploaded_photo(filename, current_user, app_config):
exif_data['Model'] if 'Model' in exif_data else None,
exif_data['Software'] if 'Software' in exif_data else None,
exif_data['DateTime'] if 'DateTime' in exif_data else None,
exif_data['DateTimeOriginal'] if 'DateTimeOriginal' in exif_data else None,
exif_data['DateTimeDigitized'] if 'DateTimeDigitized' in exif_data else None,
my_date_time_original,
my_date_time_digitized,
exif_data['fnumber'] if 'fnumber' in exif_data else None,
exif_data['DigitalZoomRatio'] if 'DigitalZoomRatio' in exif_data else None,
my_digital_zoom_ratio,
exif_data['AspectRatio'],
exif_data['TimeZoneOffset'] if 'TimeZoneOffset' in exif_data else None,
my_timezone_offset,
exif_data['GPSAltitude'] if 'GPSAltitude' in exif_data else None,
exif_data['GPSAboveSeaLevel'] if 'GPSAboveSeaLevel' in exif_data else None,
my_gps_above_sealevel,
exif_data['GPSLatitude'] if 'GPSLatitude' in exif_data else None,
exif_data['GPSLongitude'] if 'GPSLongitude' in exif_data else None,
int(time() * 1000)
@ -145,14 +170,14 @@ def process_uploaded_photo(filename, current_user, app_config):
exif_data['Model'] if 'Model' in exif_data else None,
exif_data['Software'] if 'Software' in exif_data else None,
exif_data['DateTime'] if 'DateTime' in exif_data else None,
exif_data['DateTimeOriginal'] if 'DateTimeOriginal' in exif_data else None,
exif_data['DateTimeDigitized'] if 'DateTimeDigitized' in exif_data else None,
my_date_time_original,
my_date_time_digitized,
exif_data['fnumber'] if 'fnumber' in exif_data else None,
exif_data['DigitalZoomRatio'] if 'DigitalZoomRatio' in exif_data else None,
my_digital_zoom_ratio,
exif_data['AspectRatio'],
exif_data['TimeZoneOffset'] if 'TimeZoneOffset' in exif_data else None,
my_timezone_offset,
exif_data['GPSAltitude'] if 'GPSAltitude' in exif_data else None,
exif_data['GPSAboveSeaLevel'] if 'GPSAboveSeaLevel' in exif_data else None,
my_gps_above_sealevel,
exif_data['GPSLatitude'] if 'GPSLatitude' in exif_data else None,
exif_data['GPSLongitude'] if 'GPSLongitude' in exif_data else None,
int(time() * 1000),