mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 00:53:42 +01:00
Refactor
This commit is contained in:
parent
35307dfdec
commit
9b3a02df17
@ -18,5 +18,5 @@ These are scripts I use to automate various sysadmin tasks.
|
||||
- ~seed_scihub_max_seeders.py~ : Finds which torrents have less than or equal to N seeders, where N is an integer argument supplied by the user. It then adds these torrents to a qBittorrent instance.
|
||||
- ~update_tracker.py~ : Fetches infohashes of all torrents in each qBittorrent instance referenced in the config file, and updates my public torrent tracker's whitelist.
|
||||
#+BEGIN_EXPORT html
|
||||
<a href="https://asciinema.org/a/671625" target="_blank"><img src="https://asciinema.org/a/671625.svg" /></a>
|
||||
<a href="https://asciinema.org/a/671642" target="_blank"><img src="https://asciinema.org/a/671642.svg" /></a>
|
||||
#+END_EXPORT
|
||||
|
@ -44,7 +44,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Collect infohashes of all torrents in each qBittorrent instance
|
||||
console.log(
|
||||
"Collecting infohashes of all torrents in each qBittorrent instance"
|
||||
"Collecting infohashes of all torrents in each qBittorrent instance."
|
||||
)
|
||||
torrent_infohashes = []
|
||||
for item in auth_data["instances"]:
|
||||
@ -55,11 +55,11 @@ if __name__ == "__main__":
|
||||
torrent_infohashes.append(torrent.get("hash")) # type: ignore
|
||||
|
||||
# Format the infohashes to have a \n at the end
|
||||
console.log("Formatting infohashes to have a newline at the end")
|
||||
console.log("Formatting infohashes to have a newline at the end.")
|
||||
format_infohashes = set([f"{infohash}\n" for infohash in torrent_infohashes])
|
||||
|
||||
# Create a NamedTemporaryFile and write all infohashes to it, one per line
|
||||
console.log("Creating temporary file to write infohashes to")
|
||||
console.log("Creating temporary file to write infohashes to.")
|
||||
with tempfile.NamedTemporaryFile() as ntf:
|
||||
with open(ntf.name, "w") as tf:
|
||||
tf.writelines(format_infohashes)
|
||||
@ -68,7 +68,7 @@ if __name__ == "__main__":
|
||||
# directory on the remote torrent tracker server, overwriting the
|
||||
# whitelist.txt file
|
||||
console.log(
|
||||
"SSH-copying the temporary infohashes file to the torrent tracker's whitelist"
|
||||
"SSH-copying the temporary infohashes file to the torrent tracker's whitelist."
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
@ -81,7 +81,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Use SSH to run `systemctl restart opentracker.service` on the remote
|
||||
# torrent tracker server
|
||||
console.log("Restarting opentracker.service on the remote server")
|
||||
console.log("Restarting opentracker.service on the remote server.")
|
||||
subprocess.run(
|
||||
[
|
||||
"ssh",
|
||||
@ -96,7 +96,7 @@ if __name__ == "__main__":
|
||||
# tracker list.
|
||||
if args["--add-nirn-tracker"]:
|
||||
console.log(
|
||||
"Ensuring bttracker.nirn.quest:6969/announce is added to each torrent's tracker list"
|
||||
"Ensuring bttracker.nirn.quest:6969/announce is added to each torrent's tracker list."
|
||||
)
|
||||
for item in auth_data["instances"]:
|
||||
qb = Client(item["hostname"])
|
||||
@ -108,16 +108,18 @@ if __name__ == "__main__":
|
||||
)
|
||||
|
||||
# Reannounce all torrents in each qBittorrent instance to their trackers
|
||||
console.log("Reannouncing all torrents to their trackers")
|
||||
console.log("Reannouncing all torrents to their trackers.")
|
||||
for item in auth_data["instances"]:
|
||||
qb = Client(item["hostname"])
|
||||
qb.login(username=item["username"], password=item["password"])
|
||||
torrent_infohashes = [torrent.get("hash") for torrent in qb.torrents()] # type: ignore
|
||||
qb.reannounce(torrent_infohashes)
|
||||
|
||||
console.log("Done!")
|
||||
|
||||
# Print output and make it look sexy ;)
|
||||
console = Console()
|
||||
tasks = Text("Tasks completed:\n")
|
||||
tasks = Text("\nTasks completed:\n")
|
||||
tasks.stylize("bold magenta")
|
||||
console.print(tasks)
|
||||
console.print(":white_check_mark: update the tracker's whitelist")
|
||||
|
Loading…
Reference in New Issue
Block a user