Here we will create an application that, when a PNG image is saved to a specific folder, converts the image to PDF and saves it to the output folder.
The application works with the following algorithm.
- Detects when a PNG file is saved in the
input
folder. - The saved file path is propagated to the conversion script, which converts the file to PDF.
- The converted PDF is saved in the
output
folder. - The input folder is deleted periodically to keep it clean.
See Taskick for usage.
This repository consists of the following folders.
├── LICENSE
├── README.md # This file.
├── batch.yaml
├── config
│ ├── logging.conf # Can be specified by using the -l option.
│ ├── logging.yaml # Can be specified by using the -l option.
│ ├── main.yaml # Configuration file to main processing.
│ └── welcome.yaml # Configuration file to display Welcome message at startup.
├── input # When a PNG image is saved here, png2pdf.py is executed.
├── output # Converted PDF is saved in this folder.
├── requirements.txt
└── src
└── png2pdf.py # Script to convert PNG to PDF.
Tusk and each file share functions and responsibilities as follows.
- Detects when a PNG file is saved in the
input
folder. <- Taskick(Set main.yaml)- The saved file path is propagated to the conversion script, which converts the file to PDF. <- Taskick(Execute png2pdf.py)
- The converted PDF is saved in the
output
folder. <- png2pdf.py- The input folder is deleted periodically to keep it clean. <- Taskick(rm -f input/.)
The detailed settings are configured in the following YAML(welcome.yaml
and main.yaml
) file.
welcome.yaml
Welcome_taskick: # Task name
status: 1 # Task status
commands:
- "echo $(date) Welcome to Taskick!"
- "&&"
- "echo waiting 5 seconds..."
- "&&"
- "sleep 5"
execution:
event_type: null # If event_type is NULL, it is executed only at startup.
main.yaml
remove_files_in_input_folder:
status: 1
commands:
- "rm -f input/*"
execution:
startup: true # If true, it is executed at startup.
await_task:
- "Welcome_taskick" # Set this task to run after the "Welcome_taskick" has finished running.
event_type: "time"
detail:
when: "*/1 * * * *" # Crontab format: Run every 1 minute.
png2pdf:
status: 1
commands:
- "python"
- "./src/png2pdf.py"
execution:
startup: false
event_type: "file"
propagate: true # If true, events that occur at runtime (such as the path of an edited file) are passed to the running script.
detail:
path: "./input"
recursive: false
handler: # Support all watchdog.events.*EventHandler.
name: "PatternMatchingEventHandler"
args: # This args is passed to the handler.
patterns:
- "*.png"
when: # Support created, deleted, modified, closed, moved event.
- "created"
The execution interval and the criteria for starting can be changed by simply editing the main.yaml
file.
For example,
- If you want a 5 minute interval to clean the
input
folder .
when: "*/1 * * * *"
↓
when: "*/5 * * * *"
- If you want to convert not only PNG but also JPEG files.
patterns:
- "*.png"
↓
patterns:
- "*.png"
- "*.jpeg"