Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
max_line_length = 100

11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OneDrive / Microsoft Graph configuration
ONEDRIVE_CLIENT_ID= # TODO: set your Azure app client ID
ONEDRIVE_CLIENT_SECRET= # TODO: set your Azure app client secret (if used)
ONEDRIVE_TENANT_ID=consumers # TODO: 'consumers' for personal Microsoft accounts

# When using OneDrive source
SRC_FOLDER=onedrive:/Documents/Books # TODO: OneDrive path or local folder

# Output folder for build artifacts
OUT_FOLDER=dist # TODO: output directory

42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Poetry
run: pipx install poetry
- name: Install deps
run: poetry install
- name: Lint
run: |
poetry run black --check .
poetry run flake8
- name: Type check
run: poetry run mypy avendehut
- name: Test
run: poetry run pytest --maxfail=1 --disable-warnings -q
- name: Build sample
run: |
mkdir -p examples/books
# Generate a tiny PDF
python - <<'PY'
from pypdf import PdfWriter
from pathlib import Path
src = Path('examples/books'); src.mkdir(parents=True, exist_ok=True)
writer = PdfWriter(); writer.add_blank_page(width=72, height=72); writer.add_metadata({"/Title": "CI PDF", "/Author": "CI"})
with open(src / 'ci.pdf', 'wb') as f:
writer.write(f)
PY
poetry run avendehut build --src examples/books --out dist

34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.so

# Env
.env
.venv/
venv/

# Poetry
poetry.lock

# Tests
.pytest_cache/
.coverage
coverage.xml
htmlcov/

# Build artifacts
dist/
build/
*.egg-info/

# IDE
.vscode/
.idea/

# Generated site
site/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Contributors

Thanks to everyone who has contributed to `avendehut`.

- Your Name Here

_Please add your name here when you contribute to the project._

64 changes: 64 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.

You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

6. Trademarks.
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
119 changes: 119 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,120 @@
## avendehut

A CLI tool to scan a folder of books (local or OneDrive), extract metadata, generate tags, and produce a searchable HTML catalog.

Inspired by the historical figure [Juan Hispalense (siglo XII)](https://es.wikipedia.org/wiki/Juan_Hispalense_%28siglo_XII%29), also known as Avendehut Hispanus.

### Features

- **📚 Metadata extraction**: EPUB, PDF, MOBI (extensible to other formats).
- **🏷 Automatic tag generation**: From metadata and file content.
- **🌐 HTML catalog generation**:
- Generates `index.html`, `data.json`, and static assets.
- Searchable, filterable, and responsive UI.
- Supports tag filtering, instant search, and lazy loading for large datasets.
- **⚡ Incremental builds**: Uses a `.manifest.json` to skip unchanged files.
- **☁ OneDrive integration**: Via Microsoft Graph API.
- **🔍 CLI search**: Search without opening the HTML site.
- **📤 Export catalog**: To CSV or JSON.
- **🖥 Cross‑platform**: macOS and Linux.

### Requirements

- **OS**: macOS or Linux
- **Python**: 3.10+
- **Dependency management**: Poetry
- **For OneDrive integration**:
- Microsoft account
- Microsoft Graph API app registration

### Installation

1. Clone the repository.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent This should be for development.

Ideally, I'd like to have this as a package published.

  1. Prepare CI with an action to publish package in some python repository
  2. Add here instructions to install that package

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it! I'll start making changes in this branch.

Open in Cursor Open in Web

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent still pending

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

```bash
git clone https://github.com/khnumdev/avendehut.git
cd avendehut
```
2. Install dependencies with Poetry.
```bash
poetry install
```
3. Set environment variables for OneDrive (if needed).
- `ONEDRIVE_CLIENT_ID`
- `ONEDRIVE_CLIENT_SECRET`
- `SRC_FOLDER` (OneDrive folder path)
- `OUT_FOLDER` (local output path)

### OneDrive Setup

- If `--src` points to a OneDrive path, the tool uses Microsoft Graph API.
- Required environment variables:
- `ONEDRIVE_CLIENT_ID`
- `ONEDRIVE_CLIENT_SECRET`
- `ONEDRIVE_TENANT_ID`
- `SRC_FOLDER` (OneDrive folder path)
- `OUT_FOLDER` (local output path)
- Register an app and configure permissions by following Microsoft's official docs: [Register an application](https://learn.microsoft.com/en-us/graph/auth-register-app-v2).

### CLI Commands
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent add a basic "usage" section

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it! I'll start making changes in this branch.

Open in Cursor Open in Web

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursoragent add basic usage section, to process from local and for one drive

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it! I'll start making changes in this branch.

Open in Cursor Open in Web


| Command | Description | Options |
| --- | --- | --- |
| `avendehut build` | Scans source folder, processes new/updated books, generates HTML site. | `--src <path>` (source folder), `--out <path>` (output folder), `--format html` (default), `--force` (reprocess all) |
| `avendehut watch` | Watches source folder for changes, auto‑rebuilds HTML. | Same as build plus `--interval <seconds>` |
| `avendehut clean` | Deletes generated output and manifest. | `--out <path>` |
| `avendehut open` | Opens generated HTML in default browser. | `--out <path>` |
| `avendehut search` | CLI search in local index. | `--query "<text>"`, `--tags "<tag1,tag2>"` |
| `avendehut export` | Exports catalog to CSV or JSON. | `--out <file>`, `--format csv|json` |

### Usage

```bash
# Build a catalog from a local folder
poetry run avendehut build --src ./books --out ./dist

# Open the generated HTML
poetry run avendehut open --out ./dist

# Search from the CLI
poetry run avendehut search --out ./dist --query "Dune" --tags "sci-fi,epub"

# Export catalog
poetry run avendehut export --src-out ./dist --format csv --out ./dist/catalog.csv
```

### HTML Catalog Features

- Responsive design (mobile, tablet, desktop).
- Instant search with highlighting.
- Tag filtering (multi‑select).
- Lazy loading for large datasets.
- Split `data.json` into chunks if > 5 MB.
- Keyboard shortcuts for navigation.
- Dark mode toggle.

### CI/CD Integration

- Use GitHub Actions for:
- Linting (`flake8`, `black`).
- Running tests (`pytest`).
- Building HTML output.
- Deploying to GitHub Pages (optional).

- Example workflow:
- Trigger on push to `main`.
- Install Python & Poetry.
- Run `poetry install`, `poetry run pytest`.
- If tests pass, run `avendehut build` and deploy.

### Development Guide

- Run in development mode: `poetry run avendehut --help`.
- Add new commands: extend the CLI module and register the command.
- Extend metadata extraction: add new extractor classes/modules.
- Contribute: see [`CONTRIBUTORS.md`](CONTRIBUTORS.md).

### License

Apache 2.0 License.

# avendehut
11 changes: 11 additions & 0 deletions avendehut/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""avendehut package.

CLI to scan books, extract metadata, and generate a searchable HTML catalog.
"""

__all__ = [
"__version__",
]

__version__ = "0.1.0"

43 changes: 43 additions & 0 deletions avendehut/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import annotations

import sys

import click
from rich.console import Console

from .commands.build import build_command
from .commands.watch import watch_command
from .commands.clean import clean_command
from .commands.open import open_command
from .commands.search import search_command
from .commands.export import export_command


console = Console()


@click.group(context_settings={"help_option_names": ["-h", "-help", "--help"]})
@click.version_option(package_name="avendehut")
def main() -> None:
"""avendehut - build and search a local HTML catalog of books.

Inspired by Juan Hispalense (Avendehut Hispanus).
"""


# Register subcommands
main.add_command(build_command, name="build")
main.add_command(watch_command, name="watch")
main.add_command(clean_command, name="clean")
main.add_command(open_command, name="open")
main.add_command(search_command, name="search")
main.add_command(export_command, name="export")


if __name__ == "__main__": # pragma: no cover
try:
main()
except click.ClickException as e: # pragma: no cover
console.print(f"[red]Error:[/red] {e}")
sys.exit(e.exit_code if hasattr(e, "exit_code") else 1)

Loading