-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility_manager.py
73 lines (57 loc) · 1.82 KB
/
utility_manager.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import datetime
from PIL import Image
from PIL.ExifTags import TAGS
from PIL.ExifTags import GPSTAGS
from geopy.exc import GeocoderTimedOut
from time import sleep
def get_exif(filename):
if filename.endswith(".jpg"):
image = Image.open(filename)
image.verify()
return image._getexif()
else:
return False
def get_labeled_exif(exif):
labeled = {}
for key, val in exif.items():
labeled[TAGS.get(key)] = val
return labeled
def get_geotagging(exif):
if not exif:
return "No EXIF metadata found"
# raise ValueError("No EXIF metadata found")
geotagging = {}
for idx, tag in TAGS.items():
if tag == "GPSInfo":
if idx not in exif:
return "No EXIF geotagging found"
# raise ValueError("No EXIF geotagging found")
try:
for key, val in GPSTAGS.items():
if key in exif[idx]:
geotagging[val] = exif[idx][key]
except GeocoderTimedOut:
sleep(1)
get_geotagging(exif)
return geotagging
def dms_to_dd(gps_coords, gps_coords_ref):
d, m, s = gps_coords
dd = d + m / 60 + s / 3600
if gps_coords_ref.upper() in ("S", "W"):
return -dd
elif gps_coords_ref.upper() in ("N", "E"):
return dd
else:
raise RuntimeError("Incorrect gps_coords_ref {}".format(gps_coords_ref))
def hour_between(d1, d2):
d1 = datetime.datetime.strptime(d1, "%Y-%m-%d-%")
d2 = datetime.datetime.strptime(d2, "%Y-%m-%d")
return abs((d2 - d1).hour)
def replace_all(text, dic):
for i, j in dic.items():
if j != "":
text = text.replace(i, j)
return text
def sort_file_tuples(tuples):
sorted_tuples = sorted(tuples, key=lambda x: x[1])
return sorted_tuples