added Emacs gif-screencast pattern

This commit is contained in:
Karl Voit 2020-06-05 11:44:59 +02:00
parent 71e327bcf6
commit 06bd08e10c
2 changed files with 13 additions and 1 deletions

View file

@ -171,6 +171,8 @@ class GuessFilename(object):
# Konica Minolta scan file-names: YYMMDDHHmmx
KonicaMinolta_TIME_REGEX = re.compile('(?P<truncatedyear>\d{2})(?P<month>[01]\d)(?P<day>[0123]\d)(?P<hour>[012]\d)(?P<minute>[012345]\d)(?P<index>\d).pdf')
# Emacs gif-screencast: output-2020-06-05-11:28:16.gif
GIF_SCREENCAST_REGEX = re.compile('output-' + DATESTAMP_REGEX + '-' + TIMESTAMP_REGEX + '.gif')
# 2019-12-04: "Die Presse (31.10.2019) - Unknown.pdf" -> "2019-10-31 Die Presse.pdf"
NEWSPAPER1_REGEX = re.compile('(?P<description>.+) \((?P<day>\d{2})\.(?P<month>\d{2})\.(?P<year>\d{4})\)(?P<misc>.*)\.(?P<extension>pdf)', re.UNICODE)
@ -695,6 +697,13 @@ class GuessFilename(object):
return '20' + regex_match.group('truncatedyear') + '-' + regex_match.group('month') + '-' + regex_match.group('day') + 'T' + \
regex_match.group('hour') + '.' + regex_match.group('minute') + '.' + regex_match.group('index') + "0 -- scan.pdf"
# 2020-06-05: Emacs gif-screencast: output-2020-06-05-11:28:16.gif
regex_match = re.match(self.GIF_SCREENCAST_REGEX, oldfilename)
if regex_match:
## re-use index number at the end as first digit of seconds and hope that not more than 5 documents are scanned within a minute:
return regex_match.group('year') + '-' + regex_match.group('month') + '-' + regex_match.group('day') + 'T' + \
regex_match.group('hour') + '.' + regex_match.group('minute') + '.' + regex_match.group('second') + " -- emacs screencasts.gif"
# FIXXME: more cases!

5
guessfilename_test.py Normal file → Executable file
View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python; -*-
# Time-stamp: <2020-05-29 16:28:30 vk>
# Time-stamp: <2020-06-05 11:42:16 vk>
import unittest
import logging
@ -993,6 +993,9 @@ class TestGuessFilename(unittest.TestCase):
self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename('20052915100.pdf'),
'2020-05-29T15.10.00 -- scan.pdf')
self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename('output-2020-06-05-11:28:16.gif'),
'2020-06-05T11.28.16 -- emacs screencasts.gif')
# self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename(''),
# '')