From 1b81d47b71f106e144ebc21c1fcc7ef7a157ffcb Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Sun, 25 Aug 2024 00:20:36 -0500 Subject: [PATCH] Check for availability of libgen.rs --- .envrc | 1 + .gitignore | 1 + scihub_knapsack.py | 16 ++++++++++++---- shell.nix | 5 +++++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv diff --git a/scihub_knapsack.py b/scihub_knapsack.py index 1dd7718..7aefa23 100755 --- a/scihub_knapsack.py +++ b/scihub_knapsack.py @@ -166,14 +166,22 @@ if __name__ == "__main__": # If it's a dry run, only print the knapsack's contents. Otherwise, # add the knapsack's contents to the qBittorrent instance. # When finished, print the number of items and the combined weight of all - # items in the knapsack. - if args["--dry-run"]: + # items in the knapsack. Before attempting to add items to the qBittorrent + # instance, check to see if libgen.rs is even working. If libgen.rs is down + # no torrents can be added to the qBittorrent instance, so exit with an + # notice. + if dry_run: for torrent in knapsack: - print(torrent["name"]) + print(torrent["link"]) else: + response = requests.get("https://libgen.rs") + if not response.ok: + exit( + "It appears https://libgen.rs is currently down. Please try again later." + ) for torrent in knapsack: qb.download_from_link(torrent["link"], category="scihub") - print(f"Added {torrent["name"]}") + print(f"Added {torrent['name']}") print("----------------") print(f"Count: {len(knapsack)} torrents") diff --git a/shell.nix b/shell.nix index 4fa7d92..0cf0d80 100644 --- a/shell.nix +++ b/shell.nix @@ -22,10 +22,15 @@ in pkgs.python312.buildEnv.override rec { extraLibs = [ pkgs.python312Packages.beautifulsoup4 + pkgs.python312Packages.black pkgs.python312Packages.bpython pkgs.python312Packages.docopt + pkgs.python312Packages.isort + pkgs.python312Packages.nose + pkgs.python312Packages.pytest pkgs.python312Packages.requests pkgs.python312Packages.rich + pyright python-qbittorrent ]; }