Skip to content

Instantly share code, notes, and snippets.

@dmd
Created March 5, 2022 15:37
Show Gist options
  • Save dmd/fb2c8fabebcf599d01a65b0331f259ab to your computer and use it in GitHub Desktop.
Save dmd/fb2c8fabebcf599d01a65b0331f259ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import glob
import os
import sys
import json
import googlemaps
gmaps = googlemaps.Client(key='fucku')
for file in sorted(glob.glob(sys.argv[1] + '/*.json'), key=lambda x: int(x.rsplit('-')[-1].replace('.json',''))):
with open(file) as f:
d = json.load(f)[0]
number = os.path.basename(file).replace('.json', '')
print(f'===== {number} =====')
print('Date: ' + next((d[k] for k in ('DateTimeOriginal', 'CreateDate') if k in d), 'No Date').replace(':', '-', 2))
if 'Title' in d:
print('Title: ' + d['Title'])
if 'Description' in d:
print('Desc: ' + d['Description'])
if 'Keywords' in d:
# if there's only one keyword, the json gets interpreted as a str instead of a list :(
keys = list((d['Keywords'],)) if type(d['Keywords']) is str else d['Keywords']
keys = set(keys)
if 'Daniel M Drucker' in keys:
keys.remove('Daniel M Drucker')
keys.add('Daniel Drucker')
print('Keys: ' + ', '.join(sorted(set(map(str, keys)) - set(('flickrsynced',)))))
if 'GPSLatitude' in d:
print('GPS: ' + str(d['GPSLatitude'])[:8] + ',' + str(d['GPSLongitude'])[:9])
reverse_geocode_result = gmaps.reverse_geocode((d['GPSLatitude'], d['GPSLongitude']))
print('Loc: ' + reverse_geocode_result[0]['formatted_address'])
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment