-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (34 loc) · 1.49 KB
/
main.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
from packages.img import Photo
from packages.gpx import Tracks
import glob
from datetime import datetime
from operator import attrgetter
import argparse
import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
parser = argparse.ArgumentParser()
parser.add_argument('--offset', help='date offset to adjust timestamps between gps track and pictures in H:M:S format')
parser.add_argument('--pic', help='path to a single picture or a path containing a collection of pictures', required=True)
parser.add_argument('--gpx', help='path to a single gpx file', required=True)
args = parser.parse_args()
logging.debug("Parsed arguments {}".format(args))
collection = []
if(args.offset is None):
sign = 1
dtOff = datetime.strptime('0:0:0', "%H:%M:%S")
else:
sign = -1 if args.offset.startswith('-') else 1
args.offset = args.offset[1:] if sign == -1 else args.offset
dtOff = datetime.strptime(args.offset, "%H:%M:%S")
logging.debug("Offset set to: {}".format(dtOff))
for f in glob.iglob(args.pic):
myImg = Photo(f)
myImg.setDateOffset([sign,dtOff])
collection.append(myImg)
sorted_collec = sorted(collection, key=attrgetter("date"))
g = Tracks(args.gpx)
for n in sorted_collec:
pt = g.findPointClosestToDatetime(n.getDate())
# Seems all points I'm getting from gpxs are oriented N/E ?
n.updatePosition(pt.elevation, pt.latitude, pt.longitude, "N", "E")
logging.info("Picture {} at timestamp {}, associated with: {}".format(n.fname, n.getDate(), pt))