Created
January 22, 2014 08:26
-
-
Save mamachanko/8555298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import os | |
import re | |
import shutil | |
from PIL import Image, ExifTags | |
def get_exif_data(image): | |
return { | |
ExifTags.TAGS[k]: v | |
for k, v in image._getexif().items() | |
if k in ExifTags.TAGS | |
} | |
dir_list = os.listdir('./images') | |
image_filenames = [img for img in dir_list if img.lower().endswith('.jpg')] | |
images = map(lambda img: Image.open('images/{}'.format(img)), image_filenames) | |
# Images have filenames like: "IMG_3216__14_Celsius.JPG" | |
celsius_rex = re.compile('\d+(?=\_Celsius)') | |
date_times, temperatures = [], [] | |
for image in images: | |
exif_data = get_exif_data(image) | |
date_time = datetime.strptime(exif_data['DateTime'], '%Y:%m:%d %H:%M:%S') | |
date_times.append(date_time) | |
degrees = int(celsius_rex.search(image.filename).group()) | |
temperatures.append(degrees) | |
for date_time, temperature in zip(date_times, temperatures): | |
print date_time, '|', '-' * (temperature-1), '*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment