mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +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.
|
- ~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.
|
- ~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
|
#+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
|
#+END_EXPORT
|
||||||
|
@ -44,7 +44,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Collect infohashes of all torrents in each qBittorrent instance
|
# Collect infohashes of all torrents in each qBittorrent instance
|
||||||
console.log(
|
console.log(
|
||||||
"Collecting infohashes of all torrents in each qBittorrent instance"
|
"Collecting infohashes of all torrents in each qBittorrent instance."
|
||||||
)
|
)
|
||||||
torrent_infohashes = []
|
torrent_infohashes = []
|
||||||
for item in auth_data["instances"]:
|
for item in auth_data["instances"]:
|
||||||
@ -55,11 +55,11 @@ if __name__ == "__main__":
|
|||||||
torrent_infohashes.append(torrent.get("hash")) # type: ignore
|
torrent_infohashes.append(torrent.get("hash")) # type: ignore
|
||||||
|
|
||||||
# Format the infohashes to have a \n at the end
|
# 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])
|
format_infohashes = set([f"{infohash}\n" for infohash in torrent_infohashes])
|
||||||
|
|
||||||
# Create a NamedTemporaryFile and write all infohashes to it, one per line
|
# 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 tempfile.NamedTemporaryFile() as ntf:
|
||||||
with open(ntf.name, "w") as tf:
|
with open(ntf.name, "w") as tf:
|
||||||
tf.writelines(format_infohashes)
|
tf.writelines(format_infohashes)
|
||||||
@ -68,7 +68,7 @@ if __name__ == "__main__":
|
|||||||
# directory on the remote torrent tracker server, overwriting the
|
# directory on the remote torrent tracker server, overwriting the
|
||||||
# whitelist.txt file
|
# whitelist.txt file
|
||||||
console.log(
|
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(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
@ -81,7 +81,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Use SSH to run `systemctl restart opentracker.service` on the remote
|
# Use SSH to run `systemctl restart opentracker.service` on the remote
|
||||||
# torrent tracker server
|
# torrent tracker server
|
||||||
console.log("Restarting opentracker.service on the remote server")
|
console.log("Restarting opentracker.service on the remote server.")
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
"ssh",
|
"ssh",
|
||||||
@ -96,7 +96,7 @@ if __name__ == "__main__":
|
|||||||
# tracker list.
|
# tracker list.
|
||||||
if args["--add-nirn-tracker"]:
|
if args["--add-nirn-tracker"]:
|
||||||
console.log(
|
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"]:
|
for item in auth_data["instances"]:
|
||||||
qb = Client(item["hostname"])
|
qb = Client(item["hostname"])
|
||||||
@ -108,16 +108,18 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Reannounce all torrents in each qBittorrent instance to their trackers
|
# 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"]:
|
for item in auth_data["instances"]:
|
||||||
qb = Client(item["hostname"])
|
qb = Client(item["hostname"])
|
||||||
qb.login(username=item["username"], password=item["password"])
|
qb.login(username=item["username"], password=item["password"])
|
||||||
torrent_infohashes = [torrent.get("hash") for torrent in qb.torrents()] # type: ignore
|
torrent_infohashes = [torrent.get("hash") for torrent in qb.torrents()] # type: ignore
|
||||||
qb.reannounce(torrent_infohashes)
|
qb.reannounce(torrent_infohashes)
|
||||||
|
|
||||||
|
console.log("Done!")
|
||||||
|
|
||||||
# Print output and make it look sexy ;)
|
# Print output and make it look sexy ;)
|
||||||
console = Console()
|
console = Console()
|
||||||
tasks = Text("Tasks completed:\n")
|
tasks = Text("\nTasks completed:\n")
|
||||||
tasks.stylize("bold magenta")
|
tasks.stylize("bold magenta")
|
||||||
console.print(tasks)
|
console.print(tasks)
|
||||||
console.print(":white_check_mark: update the tracker's whitelist")
|
console.print(":white_check_mark: update the tracker's whitelist")
|
||||||
|
Loading…
Reference in New Issue
Block a user