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> {}}: {pkgs ? import <nixpkgs> {}}:
with pkgs.python3Packages; with pkgs.python3Packages;
buildPythonPackage rec { buildPythonPackage rec {
name = "hb-downloader"; name = "hb-downloader";
src = ./.; src = ./.;
propagatedBuildInputs = [ requests pkgs.aria2 ]; pyproject = true;
build-system = [setuptools];
dependencies = [requests pkgs.aria2];
meta.mainProgram = "hb-downloader"; meta.mainProgram = "hb-downloader";
postInstall = '' 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-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1696426674, "lastModified": 1747046372,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra", "owner": "edolstra",
"repo": "flake-compat", "repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -21,29 +21,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1710146030, "lastModified": 1731533236,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"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",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -75,11 +57,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1709703039, "lastModified": 1762111121,
"narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=", "narHash": "sha256-4vhDuZ7OZaZmKKrnDpxLZZpGIJvAeMtK6FKLJYUtAdw=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d", "rev": "b3d51a0365f6695e7dd5cdf3e180604530ed33b4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -89,29 +71,13 @@
"type": "github" "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": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1710765496, "lastModified": 1759417375,
"narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=", "narHash": "sha256-O7eHcgkQXJNygY6AypkF9tFhsoDQjpNEojw3eFs73Ow=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7", "rev": "dc704e6102e76aad573f63b74c742cd96f8f1e6c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -124,17 +90,15 @@
"pre-commit-hooks": { "pre-commit-hooks": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore", "gitignore": "gitignore",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2"
"nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1710843117, "lastModified": 1762441963,
"narHash": "sha256-b6iKQeHegzpc697rxTPA3bpwGN3m50eLCgdQOmceFuE=", "narHash": "sha256-j+rNQ119ffYUkYt2YYS6rnd6Jh/crMZmbqpkGLXaEt0=",
"owner": "cachix", "owner": "cachix",
"repo": "pre-commit-hooks.nix", "repo": "pre-commit-hooks.nix",
"rev": "e8dc1b4fe80c6fcededde7700e6a23bcdf7f3347", "rev": "8e7576e79b88c16d7ee3bbd112c8d90070832885",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -164,21 +128,6 @@
"repo": "default", "repo": "default",
"type": "github" "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", "root": "root",

View file

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

View file

@ -1,4 +1,7 @@
#!/bin/env python #!/bin/env python
"""Simple python program for getting all links from humble bundle book bundles"""
# pylint: disable=C0103
import json import json
@ -8,24 +11,26 @@ cookie = input("Cookie String: ")
key = input("Order Key: ") key = input("Order Key: ")
response = requests.get( 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) 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"]: for book in books["subproducts"]:
name = book["human_name"] name = book["human_name"]
publisher = book["payee"]["human_name"] publisher = book["payee"]["human_name"]
if len(book["downloads"][0]["download_struct"]) > 1: if len(book["downloads"][0]["download_struct"]) > 1:
for download in book["downloads"][0]["download_struct"]: for download in book["downloads"][0]["download_struct"]:
link = download["url"]["web"] 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"{link}\n")
file.write(f" out={fileName.replace('/', ' ')}\n") file.write(f" out={file_name.replace('/', ' ')}\n")
else: else:
download = book["downloads"][0]["download_struct"][0] download = book["downloads"][0]["download_struct"][0]
link = download["url"]["web"] link: str = download["url"]["web"]
fileName = f"{name} - {publisher}.{download['name'].lower()}" file_name: str = f"{name} - {publisher}.{download['name'].lower()}"
file.write(f"{link}\n") 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 from setuptools import setup
with open('requirements.txt') as f: with open("requirements.txt", encoding="UTF-8") as f:
install_requires = f.read().splitlines() install_requires = f.read().splitlines()
setup( setup(
name = 'hb-downloader', name="hb-downloader",
version = '0.1', version="1.0",
install_requires=install_requires, 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 { pre-commit-check = pre-commit-hooks.lib.${pkgs.system}.run {
src = ./.; src = ./.;
hooks = { hooks = {
gofmt.enable = true; ruff.enable = true;
isort.enable = true; pylint = {
black.enable = true; 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"; name = "hb-downloader";
buildInputs = buildInputs = [myPython pre-commit-check.enabledPackages];
[ (pkgs.python3.withPackages (pyPkgs: with pyPkgs; [ requests mypy ])) ]; nativeBuildInputs = [pkgs.aria2 pkgs.ruff pkgs.basedpyright];
nativeBuildInputs = [ pkgs.aria2 ]; shellHook = ''
PYTHONPATH=${myPython}/${myPython.sitePackages}
${pre-commit-check.shellHook}
'';
} }