#!/usr/bin/env python # coding: utf-8 # # Is my life boring? # # When my life is interesting I take a lot of photos. Lets see if I can plot these photos to see if my life is getting more interesting. # In[1]: base_dir = "/home/visgean/Dropbox/**/*" # In[2]: import glob import os def get_extension(filename): filename, file_extension = os.path.splitext(filename) return file_extension.lower() picture_extensions = ['.jpg', '.jpeg', '.png'] pictures = list(filter( lambda f: get_extension(f) in picture_extensions, glob.iglob(base_dir, recursive=True) )) # In[3]: print('# of pics:', len(pictures)) # In[4]: import exifread with open(pictures[40], 'rb') as f: tags = exifread.process_file(f) print(tags.keys()) # In[5]: date = tags['Image DateTime'] # In[6]: print(date.values) # In[7]: from datetime import datetime datetime.strptime(str(date.values), '%Y:%m:%d %H:%M:%S') # In[8]: def parse_date(exif_info): if not exif_info: return None date = exif_info.get('Image DateTime') if not date: return None try: return datetime.strptime(str(date.values), '%Y:%m:%d %H:%M:%S').date() except: print(date) # In[9]: def get_exif(filename): try: with open(filename, 'rb') as f: return exifread.process_file(f) except: return None # In[10]: exif_data = list(map(get_exif, pictures)) # i want to iterate through these multiple times # In[11]: dates = list(map(parse_date, exif_data)) # In[12]: from collections import Counter photos_per_day = Counter(dates) # In[13]: print('Missing dates', photos_per_day[None]) del photos_per_day[None] # In[14]: print('Missing dates', photos_per_day[None]) # In[15]: from bokeh.plotting import figure, show, output_notebook output_notebook() # In[16]: time_graph = figure( title="Pics over time", background_fill_color="#E8DDCB", y_axis_label='# of pics', x_axis_label='Time', x_axis_type="datetime" ) sorted_vals = photos_per_day.most_common() time_graph.circle([x[0] for x in sorted_vals], [x[1] for x in sorted_vals]) show(time_graph) # As you can see that is a bit messy so lets try to collect it by month # In[17]: photos_per_month = Counter([datetime(d.year, d.month, 1) for d in dates if d]) # In[18]: time_graph = figure( title="Pics per month", background_fill_color="#E8DDCB", y_axis_label='# of pics', x_axis_label='Time', x_axis_type="datetime" ) sorted_vals = photos_per_month.most_common() time_graph.circle([x[0] for x in sorted_vals], [x[1] for x in sorted_vals]) show(time_graph) # In[21]: print(len(list(filter(None, dates)))) # I was only able to parse about 60% of my photos - rest of them comes from facebook or dont have dates at all :/ But its still nice to see that I am taking more and more photos.