feat: update the package a bit, conform to pep8

This commit is contained in:
CronyAkatsuki 2025-11-06 20:58:13 +01:00
parent 867786099a
commit fcf24cd5cd
6 changed files with 80 additions and 106 deletions

View file

@ -1,12 +1,16 @@
{pkgs ? import <nixpkgs> {}}:
with pkgs.python3Packages;
buildPythonPackage rec {
name = "hb-downloader";
src = ./.;
propagatedBuildInputs = [ requests pkgs.aria2 ];
pyproject = true;
build-system = [setuptools];
dependencies = [requests pkgs.aria2];
meta.mainProgram = "hb-downloader";
postInstall = ''
mv -v $out/bin/hb-downloader.py $out/bin/hb-downloader
mv -v $out/bin/hb_downloader.py $out/bin/hb-downloader
'';
}

83
flake.lock generated
View file

@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github"
},
"original": {
@ -21,29 +21,11 @@
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
@ -75,11 +57,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1709703039,
"narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=",
"lastModified": 1762111121,
"narHash": "sha256-4vhDuZ7OZaZmKKrnDpxLZZpGIJvAeMtK6FKLJYUtAdw=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d",
"rev": "b3d51a0365f6695e7dd5cdf3e180604530ed33b4",
"type": "github"
},
"original": {
@ -89,29 +71,13 @@
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1710695816,
"narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "614b4613980a522ba49f0d194531beddbb7220d3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1710765496,
"narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=",
"lastModified": 1759417375,
"narHash": "sha256-O7eHcgkQXJNygY6AypkF9tFhsoDQjpNEojw3eFs73Ow=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7",
"rev": "dc704e6102e76aad573f63b74c742cd96f8f1e6c",
"type": "github"
},
"original": {
@ -124,17 +90,15 @@
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_2",
"nixpkgs-stable": "nixpkgs-stable"
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1710843117,
"narHash": "sha256-b6iKQeHegzpc697rxTPA3bpwGN3m50eLCgdQOmceFuE=",
"lastModified": 1762441963,
"narHash": "sha256-j+rNQ119ffYUkYt2YYS6rnd6Jh/crMZmbqpkGLXaEt0=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "e8dc1b4fe80c6fcededde7700e6a23bcdf7f3347",
"rev": "8e7576e79b88c16d7ee3bbd112c8d90070832885",
"type": "github"
},
"original": {
@ -164,21 +128,6 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"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",

View file

@ -6,13 +6,18 @@
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks, ... }:
let
outputs = {
self,
nixpkgs,
flake-utils,
pre-commit-hooks,
...
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.x86_64-linux.default =
(import ./shell.nix { inherit pkgs pre-commit-hooks; });
packages.x86_64-linux.default = (import ./default.nix { inherit pkgs; });
import ./shell.nix {inherit pkgs pre-commit-hooks;};
packages.x86_64-linux.default = import ./default.nix {inherit pkgs;};
};
}

View file

@ -1,4 +1,7 @@
#!/bin/env python
"""Simple python program for getting all links from humble bundle book bundles"""
# pylint: disable=C0103
import json
@ -8,24 +11,26 @@ cookie = input("Cookie String: ")
key = input("Order Key: ")
response = requests.get(
f"https://www.humblebundle.com/api/v1/order/{key}", headers={"Cookie": cookie}
f"https://www.humblebundle.com/api/v1/order/{key}",
headers={"Cookie": cookie},
timeout=10,
)
books = json.loads(response.text)
with open("files.txt", "w") as file:
with open("files.txt", "w", encoding="UTF-8") as file:
for book in books["subproducts"]:
name = book["human_name"]
publisher = book["payee"]["human_name"]
if len(book["downloads"][0]["download_struct"]) > 1:
for download in book["downloads"][0]["download_struct"]:
link = download["url"]["web"]
fileName = f"{name} - {publisher}.{download['name'].lower()}"
file_name = f"{name} - {publisher}.{download['name'].lower()}"
file.write(f"{link}\n")
file.write(f" out={fileName.replace('/', ' ')}\n")
file.write(f" out={file_name.replace('/', ' ')}\n")
else:
download = book["downloads"][0]["download_struct"][0]
link = download["url"]["web"]
fileName = f"{name} - {publisher}.{download['name'].lower()}"
link: str = download["url"]["web"]
file_name: str = f"{name} - {publisher}.{download['name'].lower()}"
file.write(f"{link}\n")
file.write(f" out={fileName.replace('/', ' ')}\n")
file.write(f" out={file_name.replace('/', ' ')}\n")

View file

@ -1,11 +1,15 @@
"""Setup config"""
from setuptools import setup
with open('requirements.txt') as f:
with open("requirements.txt", encoding="UTF-8") as f:
install_requires = f.read().splitlines()
setup(
name = 'hb-downloader',
version = '0.1',
name="hb-downloader",
version="1.0",
install_requires=install_requires,
scripts=['hb-downloader.py',],
scripts=[
"hb_downloader.py",
],
)

View file

@ -1,17 +1,24 @@
{ pkgs ? import <nixpkgs> { }, pre-commit-hooks }:
let
{
pkgs ? import <nixpkgs> {},
pre-commit-hooks,
}: let
pre-commit-check = pre-commit-hooks.lib.${pkgs.system}.run {
src = ./.;
hooks = {
gofmt.enable = true;
isort.enable = true;
black.enable = true;
ruff.enable = true;
pylint = {
enable = true;
};
};
in pkgs.mkShell {
inherit (pre-commit-check) shellHook;
};
myPython = pkgs.python3.withPackages (pyPkgs: with pyPkgs; [requests pylint setuptools]);
in
pkgs.mkShell {
name = "hb-downloader";
buildInputs =
[ (pkgs.python3.withPackages (pyPkgs: with pyPkgs; [ requests mypy ])) ];
nativeBuildInputs = [ pkgs.aria2 ];
buildInputs = [myPython pre-commit-check.enabledPackages];
nativeBuildInputs = [pkgs.aria2 pkgs.ruff pkgs.basedpyright];
shellHook = ''
PYTHONPATH=${myPython}/${myPython.sitePackages}
${pre-commit-check.shellHook}
'';
}