expotime.py 998 Bytes
Newer Older
Stefano Costa's avatar
Stefano Costa committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import datetime
import os
import sqlite3
from os.path import join

from gi.repository import GExiv2, GLib

exif = GExiv2.Metadata()

def expowalk(dirname):
    for directory, dirnames, filenames in os.walk(dirname):
        for f in filenames:
            try:
                exif.open_path(join(directory, f))
            except GLib.Error:
                pass
            else:
                expotime_n, expotime_d = exif.get_exposure_time()
                try:
                    expotime = expotime_n / expotime_d
                except ZeroDivisionError:
                    pass
                else:
                    try:
                        expodatetime = datetime.datetime.strptime(exif.get_tag_string('Exif.Image.DateTime'), '%Y:%m:%d %H:%M:%S')
                    except TypeError:
                        pass
                    else:
                        print('{};{}'.format(expotime, expodatetime))

if __name__ == '__main__':
    expowalk('/home/steko/Immagini/')