Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add prefix/suffix to filename with timestamp and/or unique number before moving to archive folder #23

Open
spirkaa opened this issue Feb 5, 2021 · 2 comments

Comments

@spirkaa
Copy link

spirkaa commented Feb 5, 2021

Add prefix/suffix to filename with human-readable timestamp (datetime.now().strftime("%Y-%m-%d %H:%M:%S")) and/or unique number before moving to archive folder. In my opinion, all files must stay in archive folder without overwriting.

My scanner (HP 426dn) can't generate unique filename with timestamp by himself, and when he scanning to empty folder (/inbox), filename is always myscan0001.pdf, meaning after ocrmypdf-auto proccessing this file and moving it to archive folder, previously scanned file will be overwritten.

@Openhabber
Copy link

This!! in addition to that, it would be great if I could just specify the filename, so my files get names like 2022-11-12_17-22-10.pdf

@Openhabber
Copy link

Openhabber commented Nov 12, 2022

I kinda made it work by changing the following in ocrmypdf-auto.py:

   def _map_output_path(self, input_path):
        if self.output_mode == AutoOcrScheduler.MIRROR_TREE:
            return self.output_dir / (input_path - self.input_dir)
        else:
            assert self.output_mode == AutoOcrScheduler.SINGLE_FOLDER
#            output_path = self.output_dir / (input_path.name)
            output_path = self.output_dir / '{}{}'.format(datetime.now().strftime('%Y-%m-%d_%H-%M-%S'),input_path.suffix)
            unique = 1
#            if output_path.exists() or output_path in self.current_outputs:
#                suffix = '.{}.{}{}'.format(datetime.now().strftime('%Y%m%d'), unique, output_path.suffix)
#               output_path = output_path.with_suffix(suffix)

            while output_path.exists() or output_path in self.current_outputs:
                unique = unique + 1
                output_path = self.output_dir / '{}_{}{}'.format(datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), unique,input_path.suffix)
#               output_path = output_path.with_suffix('.{}{}'.format(unique, output_path.suffix), depth=2)
            return output_path

I then mapped it to the container (docker compose):

volumes:      
      - "/path/to/modded/file/ocrmypdf-auto_modded.py:/app/ocrmypdf-auto.py"
      - "/etc/localtime:/etc/localtime:ro"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants