Initial commit

This commit is contained in:
steven carpenter 2025-08-10 19:13:01 -04:00
commit cf83801dd1
5 changed files with 110 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.direnv
GoCalTui
bin
result
data

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1735563628,
"narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

50
flake.nix Normal file
View file

@ -0,0 +1,50 @@
# flake.nix
{
description = "Dev shell + runnable app for merge_pdfs.py";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSystem = f: nixpkgs.lib.genAttrs systems (system:
let
pkgs = import nixpkgs { inherit system; };
python = pkgs.python311.withPackages (ps: [ ps.pypdf2 ]);
# Small wrapper so `nix run` works: it uses the Python with PyPDF2 and your script.
merge-pdfs = pkgs.writeShellScriptBin "merge-pdfs" ''
exec ${python}/bin/python ${./merge_pdfs.py} "$@"
'';
in f pkgs python merge-pdfs
);
in {
devShells = forEachSystem (pkgs: python: merge-pdfs: {
default = pkgs.mkShell {
packages = [
python # Python 3.11 with PyPDF2
pkgs.ruff # optional: linter
pkgs.pyright # optional: type checker
];
shellHook = ''
echo " Dev shell ready. Try:"
echo " python merge_pdfs.py output.pdf a.pdf b.pdf"
'';
};
});
# `nix run` makes it easy to use from anywhere:
apps = forEachSystem (pkgs: python: merge-pdfs: {
default = {
type = "app";
program = "${merge-pdfs}/bin/merge-pdfs";
};
});
# expose the tiny wrapper as a package if you want `nix build .#merge-pdfs`
packages = forEachSystem (pkgs: python: merge-pdfs: {
default = merge-pdfs;
merge-pdfs = merge-pdfs;
});
};
}

27
merge_pdfs.py Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
import sys
from PyPDF2 import PdfMerger
def merge_pdfs(output_path, input_paths):
merger = PdfMerger()
for pdf in input_paths:
try:
merger.append(pdf)
print(f"Added: {pdf}")
except FileNotFoundError:
print(f"Error: File not found - {pdf}")
except Exception as e:
print(f"Error adding {pdf}: {e}")
merger.write(output_path)
merger.close()
print(f"Merged PDF saved as: {output_path}")
if __name__ == "__main__":
if len(sys.argv) < 4:
print("Usage: python merge_pdfs.py output.pdf file1.pdf file2.pdf [file3.pdf ...]")
sys.exit(1)
output_pdf = sys.argv[1]
input_pdfs = sys.argv[2:]
merge_pdfs(output_pdf, input_pdfs)