Get Wikimapia URL from EXIF

I don't know if it is useful or not, but I needed this. This scripts generates Wikimapia URLs from EXIFs in JPGs (in current directory):

IMG_20180401_113622.jpg
http://wikimapia.org/#lang=en&lat=46.47518155555556&lon=30.75603863888889
IMG_20180401_115358.jpg
http://wikimapia.org/#lang=en&lat=46.477886194444444&lon=30.74492452777778
IMG_20180401_143108.jpg
http://wikimapia.org/#lang=en&lat=46.473026250000004&lon=30.759717916666666

Python 3. Run pip install exif before:

pip3 install exif
from exif import Image
import sys

def f (fname):
    with open(fname, 'rb') as image_file:
        my_image = Image(image_file)

    assert my_image.has_exif
    lat=my_image.gps_latitude[0] + my_image.gps_latitude[1]/60 + my_image.gps_latitude[2]/3600 
    lon=my_image.gps_longitude[0] + my_image.gps_longitude[1]/60 + my_image.gps_longitude[2]/3600

    #print (lat)
    #print (lon)
    print (fname)
    print ("http://wikimapia.org/#lang=en&lat="+str(lat)+"&lon="+str(lon))

import glob
for fname in sorted(glob.glob("*.jpg")):
    try:
        f (fname)
    except AttributeError:
        print ("AttributeError for", fname)

(Updated 20221023: AttributeError catched now.)


List of my other blog posts.

Yes, I know about these lousy Disqus ads. Please use adblocker. I would consider to subscribe to 'pro' version of Disqus if the signal/noise ratio in comments would be good enough.