#! /usr/bin/python -tt
# Copyright (C) 2014 Nathan Paul Simons (C2T9uE-code@hardcorehackers.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""Simple template."""
# Turn on all warnings.
import warnings
warnings.simplefilter("always")
from glob import glob
def generate_header(title):
return """
{0}
""".format(title)
def generate_gps_tracks_input(gps_track_filenames):
result = """var gpx;
"""
for filename in gps_track_filenames:
track_lines = """gpx = '{0}';
new L.GPX(gpx, {{async: true}}).on('loaded', function(e) {{
map.fitBounds(e.target.getBounds());
}}).addTo(map);
""".format(filename)
result = result + track_lines
return result
def find_image_webpage(image_name):
search = "{0}_Sm.jpg.*.html".format(image_name)
found = glob(search)[0]
return found
def re_round(li, _prec=6):
"""
Taken from
http://stackoverflow.com/questions/24642669/python-quickest-way-to-round-every-float-in-nested-list-of-tuples
"""
try:
return round(li, _prec)
except TypeError:
return type(li)(re_round(x, _prec) for x in li)
def generate_image_popups(image_filenames):
result = """var img;
"""
from get_lat_lon_exif import get_lat_lon, get_exif_data
from os.path import splitext
import Image
generate_image_popups.prev_lat_lons = []
for filename in image_filenames:
image = Image.open(filename)
(width, height) = Image.open("{0}_pre.jpg".format(splitext(filename)[0])).size
lat_lon = get_lat_lon(get_exif_data(image))
if lat_lon[0] and lat_lon[1]:
if not lat_lon in generate_image_popups.prev_lat_lons:
generate_image_popups.prev_lat_lons.append(lat_lon)
image_lines = """img = new L.marker([{0}, {1}]).addTo(map);
img.bindPopup("")
""".format(lat_lon[0],
lat_lon[1],
find_image_webpage(splitext(filename)[0]),
splitext(filename)[0],
height,
width)
result = result + image_lines
return result
def generate_body(image_filenames,
gps_track_filenames):
result="""
"""
def _test():
"""
Simple default test routine.
"""
import doctest
doctest.testmod(verbose=True)
if __name__ == "__main__":
"""
Main entry if called standalone.
"""
from sys import argv
print generate_header(argv[1])
print generate_body(sorted(glob('[0-9]' * 8 + '_' + '[0-9]' * 6 + ".jpg") + glob("IMG_" + '[0-9]' * 4 + ".jpg")),
glob("*.gpx"))
print generate_footer()
# Local Variables:
# mode: Python; tab-width: 4
# End:
# vi: fileformat=unix shiftwidth=4 tabstop=4 expandtab