Commit Graph
172 Commits
Author SHA1 Message Date
72f8254e10 US0: Paperless-ngx Initial Import - Reusable Components + Import Script (#9)
* Add sidecar.py module for User Story 0 (Paperless-ngx import)

Implements the sidecar data model, schema validation, atomic writes,
and I/O helpers per PRD section 7.

- Sidecar and SidecarEvent dataclasses with full PRD schema
- SidecarStatus and EventType enums
- build_sidecar(), serialize(), deserialize() functions
- validate_sidecar() with type and required field checking
- get_sidecar_key() for .meta.json suffix generation
- write_atomic() for crash-safe temp-key + copy + delete pattern
- read_sidecar(), sidecar_exists(), matching_sha256() for storage I/O

This is a reusable component for both the import script and main service.

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Add storage/ module with S3 and File backends

Implements the storage layer abstraction for User Story 0.

- StorageBackend ABC: defines interface for all storage implementations
- S3Storage: boto3-based backend for Garage S3 (production)
- FileStorage: filesystem-based backend for testing
- get_storage_backend() factory function
- Atomic operations: put, get, delete, copy, exists, list, head

Both backends implement the same interface, allowing seamless
switching between production S3 and local testing.

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Add period.py, extractor.py, and config.py reusable modules

- period.py: Period parsing from filenames and computation from dates
  - parse_period_from_filename(): Extracts month-year, quarter, year, date patterns
  - compute_period_from_date(): Computes period per template rules (granularity + offset)
  - get_period(): Main entry point with filename fallback to rule-based computation
  - validate_period_consistency(): Checks period vs emission_date + rule
  - Supports French month names (août, janvier, etc.)

- extractor.py: PDF text extraction using PyMuPDF
  - extract_first_page_text(): Extracts text from first PDF page
  - extract_and_validate(): Extracts and checks minimum text length
  - TextExtractor class for dependency injection and mocking

- config.py: Configuration management
  - S3Config, PaperlessConfig, PollerConfig, ClassifierConfig dataclasses
  - AppConfig: Main application configuration from env vars
  - TemplateRegistry: Loads and manages template YAML configurations
  - load_config(), load_templates() helper functions

All modules are reusable by both import script and main service.

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Add import_paperless.py script for User Story 0

Implements the standalone import script that:
- Connects to Paperless-ngx REST API (PAPERLESS_URL + token from env)
- Connects to Garage S3 bucket via boto3 (S3_ENDPOINT_URL, credentials, bucket)
- Lists all documents from Paperless via paginated /api/documents/
- Fetches document metadata and maps to sidecar fields:
  - template: first path segment of storage_path
  - emission_date: document created field
  - emitting_company: correspondent name
  - document_type: document type name
  - period: parsed from filename tail, fallback to month-year from emission_date
  - extracted_text: first page text via PyMuPDF
  - optional_fields: from Paperless labels
- Downloads PDF via /api/documents/{id}/download/
- Stores PDF at files/{template}/{original filename}
- Writes sidecar {key}.meta.json with atomic temp-key + copy pattern
- Supports resumability (skip if PDF + sidecar exist with matching SHA256)
- Dry-run flag for testing
- Limit flag for trial runs
- Summary reporting at end
- Exit code: 0 if all succeed, 1 if any failures

Dependencies: requests, boto3, pymupdf, python-dateutil

Usage: python scripts/import_paperless.py [--dry-run] [--limit N] [--verbose]
Environment: PAPERLESS_URL, PAPERLESS_TOKEN, S3_ENDPOINT_URL, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_BUCKET_NAME

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Add requirements.txt for import script dependencies

Lists all Python dependencies needed to run scripts/import_paperless.py:
- requests: Paperless-ngx API client
- boto3: Garage S3 client
- pymupdf: PDF text extraction
- python-dateutil: Date parsing
- PyYAML: YAML config parsing (optional)

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Update import script: add storage backend selection (s3/file)

- Added --storage-backend argument (choices: s3, file, default: s3)
- Added --file-base-dir argument for file storage
- Storage backend validation based on selection
- Updated help text and epilog with backend-specific env vars
- Importer class now accepts storage_backend and file_base_dir params
- _init_storage() method handles backend initialization
- Summary now shows which storage backend was used

Usage examples:
  # S3 storage (default)
  python scripts/import_paperless.py

  # File storage for testing
  python scripts/import_paperless.py --storage-backend file --file-base-dir ./test_storage

  # Explicit S3
  python scripts/import_paperless.py --storage-backend s3 --s3-endpoint ... --s3-bucket ...

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Add README.md for scripts directory

Comprehensive documentation for import_paperless.py script:
- Overview and features
- Requirements and installation
- Usage examples (env vars + CLI args)
- Storage backends (S3 vs file)
- Metadata mapping table
- Output structure
- Resumability notes
- Exit codes
- Example output
- Troubleshooting guide
- Development/testing notes
- Architecture overview

Helps users understand how to use the import script for User Story 0.

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Fix Paperless API field mapping

The Paperless-ngx API returns IDs for correspondent, document_type, and tags,
not the actual string values. This commit fixes the import script to:

- Use 'archived_file_name' instead of 'filename' for the actual filename
- Fetch correspondent name from /api/correspondents/{id}/ endpoint
- Fetch document type name from /api/document_types/{id}/ endpoint
- Fetch tag names from /api/tags/{id}/ endpoint
- Add caching for fetched entities to avoid duplicate API requests

This ensures the sidecar metadata contains actual human-readable strings
instead of numeric IDs.

Changes:
- PaperlessClient: Added get_correspondent_name(), get_document_type_name(), get_tag_name()
- PaperlessClient: Added caches for fetched entities
- get_all_documents(): Now resolves IDs to names for all fields
- Updated module docstring to document this behavior

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* Refactor PaperlessClient: change labels to list, add storage path caching, and improve document fetching logic

---------

Co-authored-by: Vibe Nuage Agent <vibe@mistral.ai>
Co-authored-by: napnap75 <napnap75@users.noreply.github.com>
2026-10-03 10:05:49 +02:00
thomas 2d26876bf5 Add architecture document and user story for paperless-ngx import 2026-10-01 22:54:42 +02:00
thomas 36df49048c Manually corrected the brief and prd 2026-10-01 19:11:56 +02:00
thomas b704403a8a New version to use s3 as the source of truth 2026-10-01 15:04:27 +02:00
thomas 112c3be824 Add project brief and requirements in MD format (#8) 2026-10-01 15:01:48 +02:00
thomas 732ba6de0a Initial project specifications for PDF renamer (#7) 2026-10-01 14:14:00 +02:00
thomas c3a3ac922e Update CI workflow triggers for main branch 2026-10-01 14:03:57 +02:00
thomas 34b63e938d Added the procps package to make the healthchecks work 2026-09-26 14:02:55 +02:00
thomas 35aa32389a fix: Simplify timestamp parsing by removing timezone and format configuration 2026-09-08 23:41:10 +02:00
thomas 701b5b077f Split configuration to manage different time format 2026-09-08 23:27:48 +02:00
thomas f4c2628e0c fix: Improve log fetching by filtering timestamps 2026-09-06 13:11:31 +02:00
thomas a3402c85d6 Removed duplicate notification of logs that are outside the specified time range. 2026-08-31 22:23:04 +02:00
thomas a5337c3d29 feat: Refactor log-alert application into modular structure
- Introduced alerters package with base Alerter class and implementations for LogAlerter and GotifyAlerter.
- Created fetchers package with abstract LogFetcher class and implementations for FileLogFetcher, LokiLogFetcher, and ParseableLogFetcher.
- Added filters package with base Filter class and implementations for RegexpFilter and GeolocationFilter.
- Implemented rules package with base AlertRule class and SimpleAlertRule for alerting logic.
- Enhanced configuration handling with utilities for loading and validating JSON configuration.
- Updated logging setup for better logging management.
- Modified main application logic to utilize the new modular structure, improving maintainability and readability.
- Updated config.json and config.schema.json to reflect changes in alerting and fetching configurations.
- Added python-dateutil to requirements for date parsing functionality.
2026-08-30 23:22:38 +02:00
thomas b7f1b97434 Use RESTIC_HOST for notifications instead of HOSTNAME 2026-08-22 23:22:35 +02:00
thomas c9892bfd81 Updated rsync-server 2026-08-21 13:56:06 +02:00
thomas 8e1dee24d4 Remove quiet mode from restic backup commands 2026-06-24 20:54:52 +02:00
thomas 1ebe65fc80 Allow the use of templates for the alert title 2026-05-10 12:26:02 +02:00
thomas 0fee65bc93 Update Dockerfile to use latest Golang Alpine image 2026-05-01 19:19:02 +02:00
thomas 2d62c94031 Allow restic to be run from outside 2026-04-19 23:12:19 +02:00
thomas c7d46d7186 Reduced the output 2026-03-29 13:03:47 +02:00
thomas e1d9f968a9 Refactor error logging to use fmt.Println for consistency 2026-01-23 22:56:26 +01:00
thomas 1bb341b14e Enhance recipe4reader: Add image handling and improve Markdown conversion 2026-01-11 23:11:43 +01:00
thomas e81a5ff3cc Added recipe4reader 2026-01-11 18:27:59 +01:00
thomas 285aa5be0c Added the ability to backup inside the restic container 2025-12-18 23:02:51 +01:00
thomas 89bc68631a Improve WhatsApp connection handling 2025-10-18 23:53:57 +02:00
thomas b2d515a460 New simplified version 2025-10-18 18:08:21 +02:00
thomas 06ca841919 New simplified version 2025-10-18 18:03:49 +02:00
thomas 227f1d48e1 Added the geolocation filter and improved the config file format 2025-10-18 15:43:33 +02:00
thomas b06a39df3a Improved logging 2025-10-17 23:32:11 +02:00
thomas 7de812d002 Add jsonschema validation (#6)
* Add JSON Schema validation for log-alert config and require jsonschema

* Add jsonschema dependency to requirements

* Enhance config loading with schema validation

Added JSON schema validation for configuration and improved error handling.

* Simplify token assignment and config loading

Refactor token retrieval and configuration loading.
2025-10-16 21:02:28 +02:00
thomas c67b2b54c8 Upgraded version 2025-10-16 00:03:31 +02:00
thomas 0b5559be69 First version of log-alert 2025-10-15 22:32:51 +02:00
thomas 8385c5fb1d First version of log-alert 2025-10-15 22:30:08 +02:00
thomas 2f34fbac5f Removed ssh-chrooted 2025-08-31 22:11:05 +02:00
thomas 08cc0db5ec Revert to alpine 3.21 2025-08-17 14:54:46 +03:00
thomas a659f3c084 Revert to Alpine 3.21 2025-08-17 14:40:30 +03:00
thomas 83240a5bc4 Added a check not to backup the root directory 2025-07-06 13:07:31 +02:00
thomas be38f711b7 Refactored the code 2025-06-20 23:16:32 +02:00
thomas 7ea5713bf5 Updated GO version to correct the build 2025-06-19 23:05:06 +02:00
thomas c8f24c08ec Corrrected the script 2025-06-19 21:32:13 +02:00
thomas 99c016dba9 Corrected the script 2025-06-17 00:06:45 +02:00
thomas 6299e4e01a Update GO version 2025-06-16 20:17:54 +02:00
thomas fe23e93e4a Ouputs logs to stdout 2024-10-21 22:51:40 +02:00
thomas 0cd3523438 Simplified the script by adding Runitor 2024-10-11 22:07:15 +02:00
thomas 163ae5a8bf Simplified the script by adding Runitor 2024-10-11 22:05:11 +02:00
thomas 56037ebe0f Delete immich-souvenirs/README.md 2024-10-10 09:06:52 +02:00
thomas aa87ef2969 Added runitor to handle HC pings 2024-10-06 15:20:35 +02:00
thomas 3ec4250f24 Removed the unused images 2024-10-02 18:02:22 +02:00
thomas dafa972661 Updated the GO version 2024-10-02 08:20:20 +02:00
thomas d4926240ab Now send the logs to a file 2024-09-25 17:45:43 +02:00