From 9a0499b90f7365bfa6599b60ed5abca93122856d Mon Sep 17 00:00:00 2001 From: Karl Voit Date: Thu, 10 Oct 2019 13:44:30 +0200 Subject: [PATCH] added PDF file patterns for Boox Max 2 exports --- guessfilename/__init__.py | 21 ++++++++++++++++++++- guessfilename_test.py | 10 +++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/guessfilename/__init__.py b/guessfilename/__init__.py index beadd87..db38529 100755 --- a/guessfilename/__init__.py +++ b/guessfilename/__init__.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -PROG_VERSION = u"Time-stamp: <2019-09-30 10:04:46 vk>" +PROG_VERSION = u"Time-stamp: <2019-10-10 13:33:37 vk>" # TODO: @@ -1049,6 +1049,25 @@ class GuessFilename(object): return datetimestr + ' ' + self.config.SALARY_DESCRIPTION + ' MONTH - SALARY' + \ '€ -- detego private.pdf' + # 2019-10-10: '2019-10-10 a file exported by Boox Max 2-Exported.pdf' or + # '2019-10-10 a file exported by Boox Max 2 -- notes-Exported.pdf' become + # -> '2019-10-10 a file exported by Boox Max 2 -- notes.pdf' + if extension.upper() == "PDF" and oldfilename.upper().endswith('-EXPORTED.PDF'): + if self.contains_all_of(oldfilename, [" -- ", " notes"]): + # FIXXME: assumption is that "notes" is within the + # filetags and not anywhere else: + # '2019-10-10 a file exported by Boox Max 2 -- notes-Exported.pdf' + return oldfilename[:-13] + '.pdf' + else: + if ' -- ' in oldfilename: + # filetags found but not containing "notes": + # '2019-10-10 a file exported by Boox Max 2 -- draft-Exported.pdf' + return oldfilename[:-13] + ' notes.pdf' + else: + # no filetags found so far: + # '2019-10-10 a file exported by Boox Max 2-Exported.pdf' + return oldfilename[:-13] + ' -- notes.pdf' + # FIXXME: more cases! return False # no new filename found diff --git a/guessfilename_test.py b/guessfilename_test.py index 0f49e10..208ef46 100644 --- a/guessfilename_test.py +++ b/guessfilename_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python; -*- -# Time-stamp: <2019-09-30 10:08:44 vk> +# Time-stamp: <2019-10-10 13:30:31 vk> import unittest import logging @@ -220,6 +220,14 @@ class TestGuessFilename(unittest.TestCase): self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename('IMG_20190118_133928_Bokeh This is a note.jpg'), '2019-01-18T13.39.28 Bokeh This is a note.jpg') + self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename('2019-10-10 a file exported by Boox Max 2-Exported.pdf'), + '2019-10-10 a file exported by Boox Max 2 -- notes.pdf') + self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename('2019-10-10 a file exported by Boox Max 2 -- notes-Exported.pdf'), + '2019-10-10 a file exported by Boox Max 2 -- notes.pdf') + self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename('2019-10-10 a file exported by Boox Max 2 -- draft-Exported.pdf'), + '2019-10-10 a file exported by Boox Max 2 -- draft notes.pdf') + + # self.assertEqual(self.guess_filename.derive_new_filename_from_old_filename(''), # '')