commit 763d2110c84041dc733f3bfb692e91cb8ccff9e9 Author: Khaïs COLIN Date: Fri Dec 5 22:17:27 2025 +0100 it works diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bbdbfe --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.direnv +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d865d9a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1764915887, + "narHash": "sha256-CeBCJ9BMsuzVgn8GVfuSRZ6xeau7szzG0Xn6O/OxP9M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "42e29df35be6ef54091d3a3b4e97056ce0a98ce8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8f72e6b --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + description = "scan! and organize!"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages.default = let + name = "scansnapit"; + src = pkgs.lib.readFile ./scan.fish; + script = pkgs.writeScriptBin name src; + runtimeInputs = [pkgs.jq (pkgs.llm.withPlugins {llm-ollama = true;}) pkgs.ocrmypdf pkgs.imagemagick]; + in + pkgs.symlinkJoin + { + inherit name; + paths = [script] ++ runtimeInputs; + buildInputs = [pkgs.makeWrapper]; + postBuild = "wrapProgram $out/bin/${name} --prefix PATH : $out/bin"; + }; + } + ); +} diff --git a/scan.fish b/scan.fish new file mode 100755 index 0000000..32d910c --- /dev/null +++ b/scan.fish @@ -0,0 +1,42 @@ +#!/usr/bin/env fish + +set -x OLLAMA_HOST 100.70.78.2:11434 + +set date (date -I) +set timestamp (date +%H:%M:%S) +set basedir $HOME/scans/.in-progress/$date/$timestamp + +mkdir -p $basedir + +pushd $basedir + +scanimage -d fujitsu -b -p --format=png --source='ADF Duplex' --page-width=219.428 --page-height=297 --mode=Color --resolution=300dpi --buffermode=On + +echo "Creating pdf..." +magick out*.png paper.pdf; or exit +rm *.png +ocrmypdf --clean-final --deskew --rotate-pages -l fra+eng+deu --sidecar paper.txt paper.pdf paper.pdf + +echo "Now doing AI naming..." + +head -n 100 paper.txt | llm -t docname +llm logs -c --data >title.json +set title (jq -r '"\(.date_creation) \(.createur) - \(.titre)"' < title.json) + +echo $title + +# cat paper.txt | OLLAMA_HOST=100.70.78.2:11434 llm -t doctask >"$title - task.txt" +# cat "$title - task.txt" + +mv paper.pdf $title.pdf +mv paper.txt $title.txt + +popd + +echo "Moving files..." + +set outdir "$HOME/scans/$date/$title" + +mkdir -p $outdir +mv $basedir/* $outdir +rmdir $basedir