I use dateutil to analyze images and sort them by date. Since not all of my photos have metadata, dateutil tries to guess where to put them.
Most of my photos in this format: 2007-09-10_0001.jpg 2007-09-10_0002.jpg, etc ...
fileName = os.path.splitext(file)[0] print("Guesssing date from ", fileName) try: dateString = dateParser.parse(file, fuzzy=True) print("Guessed date", dateString) year=dateString.year month = dateString.month day=dateString.day except ValueError: print("Unable to determine date of ", file)
The return I receive is the following:
('Guesssing date from ', '2007-09-10_00005') ('Unable to determine date of ', '2007-09-10_00005.jpg')
Now I can remove everything due to underlining, but I would like to get a more reliable solution, if possible, if I have photos in a different format. I, although fuzzy, tried to find any date in the string and match this, but apparently does not work ...
Is there an easy way to get the analyzer to find something like a date and stop after that? If not, what is the easiest way to make the parser ignore everything after underscore? Or a way to define multiple date formats with ignore sections.
Thanks!
source share