-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcustom-field-sum.py
More file actions
33 lines (25 loc) · 829 Bytes
/
Copy pathcustom-field-sum.py
File metadata and controls
33 lines (25 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import os
import asyncio
from pypaperless import Paperless
PAPERLESS_URL = os.environ["PAPERLESS_URL"]
PAPERLESS_TOKEN = os.environ["PAPERLESS_TOKEN"]
# Custom field IDs to sum up
CUSTOM_FIELD_ID = 1
# Visit https://your-paperless-url/api/documents in your browser
# to discover all available filters
filters = {
"tags__id": 38,
"document_type__id": 3,
"created__date__gt": "2023-10-01",
"created__date__lt": "2023-12-31"
}
async def main():
paperless = Paperless(PAPERLESS_URL, PAPERLESS_TOKEN)
async with paperless:
async with paperless.documents.reduce(**filters) as filtered:
sum = 0
async for doc in filtered:
sum += [f.value for f in doc.custom_fields if f.field == CUSTOM_FIELD_ID][0]
print(sum)
asyncio.run(main())