Skip to content

Commit c40617d

Browse files
Replace custom script with Paperless-ngx CLI
1 parent 1f74ed4 commit c40617d

File tree

4 files changed

+13
-101
lines changed

4 files changed

+13
-101
lines changed

docs/post-consumption/content-matching.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,28 @@ Paperless-ngx does a great job matching documents with correct correspondents, s
88
However, there are documents for which the automatic matching doesn't work or a single regular expression match isn't sufficient.
99
For such cases, further examining the document's content after consumption is necessary.
1010

11-
## Update document details via organize
11+
## Update document details via organize and the Paperless-ngx CLI
1212

1313
[organize](https://github.com/tfeldmann/organize) is an open-source, command-line file management automation tool.
1414
It allows to execute certain actions based on custom filters. These can be easily defined in YAML.
1515

16-
Probably the most helpful filter in this context is the `filecontent` filter. The document's content can be matched with regular expressions
17-
which allows to dynamically re-use (parts of) the matched content in subsequent actions.
16+
Probably the most helpful filter in this context is the `filecontent` filter. The document's content can be matched with regular expressions which allows to dynamically re-use (parts of) the matched content in subsequent actions.
1817

1918
Following script
2019

2120
1. ensures that a newly-consumed document gets assigned a proper title based on the document's content.
2221
This helps to stick to a consistent naming pattern for documents that you receive regularly, e.g. invoices.
2322
2. extracts a value out of the document content and stores it in a given custom field
2423

24+
The Paperless-ngx CLI can be used to update other fields as well. Check the CLI's help or [GitHub repository](https://github.com/marcelbrueckner/paperless-ngx-cli) for more information.
25+
2526
### Prerequisites
2627

2728
For this solution to work, you will need to install the following packages:
2829

2930
* [organize-tool](https://pypi.org/project/organize-tool/)
3031
* [poppler](https://poppler.freedesktop.org/)[^1]
32+
* [pypaperless-cli](https://pypi.org/project/pypaperless-cli/)
3133

3234
[^1]: Poppler is required for organize's `filecontent` filter to work, see [https://github.com/tfeldmann/organize/issues/322](https://github.com/tfeldmann/organize/issues/322).
3335

@@ -41,8 +43,7 @@ Sticking to the general idea of our scripts folder layout, we will end up with f
4143
paperless-ngx/
4244
├─ my-post-consumption-scripts/
4345
│ ├─ organize/
44-
│ │ ├─ organize.config.yml.tpl
45-
│ │ └─ pngx-update-document.py
46+
│ │ └─ organize.config.yml.tpl
4647
│ └─ post-consumption-wrapper.sh
4748
# Obviously the below file only exists
4849
# if you're running Paperless-ngx via Docker Compose
@@ -57,9 +58,10 @@ paperless-ngx/
5758

5859
```bash
5960
# Token to access the REST API
60-
PAPERLESS_TOKEN=
61+
PNGX_TOKEN=
6162
# Your Paperless-ngx URL, without trailing slash
62-
PAPERLESS_URL=
63+
# If running your post-consumption script within Docker, its likely to be http://localhost:8000
64+
PNGX_HOST=
6365
```
6466

6567
=== "organize.config.yml.tpl"
@@ -68,12 +70,6 @@ paperless-ngx/
6870
--8<-- "scripts/post-consumption/content-matching/organize.config.yml.tpl"
6971
```
7072

71-
=== "pngx-update-document.py"
72-
73-
```python
74-
--8<-- "scripts/post-consumption/content-matching/pngx-update-document.py"
75-
```
76-
7773
=== "post-consumption-wrapper.sh"
7874

7975
```bash
@@ -89,4 +85,3 @@ paperless-ngx/
8985
## Notes
9086

9187
Script files can also be found on [GitHub](https://github.com/marcelbrueckner/paperless.sh/tree/main/scripts/post-consumption/content-matching).
92-

scripts/post-consumption/content-matching/10-install-additional-packages.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
# Add additional information to consumed documents
66
# based on hypercomplex ;) rules
77
# https://github.com/tfeldmann/organize/
8+
# https://github.com/marcelbrueckner/paperless-ngx-cli
89
apt-get install poppler-utils
9-
pip install organize-tool
10+
pip install --root-user-action=ignore organize-tool
11+
pip install --root-user-action=ignore pypaperless-cli

scripts/post-consumption/content-matching/organize.config.yml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ rules:
2020
- filecontent: 'Amount due.*(?P<amount>\d{2}\.\d{2})'
2121
actions:
2222
- echo: "Home Assistant hooray"
23-
- shell: "./pngx-update-document.py --url http://localhost:8000 --document-id {env.DOCUMENT_ID} --title '{filecontent.title}' --custom-field-id 1 --custom-field-value {filecontent.amount}"
23+
- shell: "pngx edit {env.DOCUMENT_ID} --title '{filecontent.title}' --custom-fields 1={filecontent.amount}"
2424
- echo: "{shell.output}"

scripts/post-consumption/content-matching/pngx-update-document.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)