update, remove active
This commit is contained in:
parent
e0e4fb007c
commit
f615db3167
|
|
@ -10,13 +10,11 @@ qb_urls = [
|
||||||
|
|
||||||
def get_uploaded(qb_url, auth_type):
|
def get_uploaded(qb_url, auth_type):
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
active = False
|
|
||||||
total_uploaded = 0
|
total_uploaded = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = session.get(qb_url["url"])
|
response = session.get(qb_url["url"])
|
||||||
if response.status_code != 200:
|
response.raise_for_status()
|
||||||
raise Exception("Server not reachable")
|
|
||||||
|
|
||||||
if auth_type == "http":
|
if auth_type == "http":
|
||||||
auth = HTTPBasicAuth(os.getenv("HTTP_USERNAME"), os.getenv("HTTP_PASSWORD"))
|
auth = HTTPBasicAuth(os.getenv("HTTP_USERNAME"), os.getenv("HTTP_PASSWORD"))
|
||||||
|
|
@ -27,13 +25,14 @@ def get_uploaded(qb_url, auth_type):
|
||||||
raise Exception("Login failed")
|
raise Exception("Login failed")
|
||||||
response = session.get(f"{qb_url['url']}/api/v2/torrents/info")
|
response = session.get(f"{qb_url['url']}/api/v2/torrents/info")
|
||||||
|
|
||||||
active = True
|
total_uploaded = sum(
|
||||||
total_uploaded = sum(torrent["uploaded"] for torrent in response.json() if any(keyword.lower() in torrent["name"].lower() for keyword in ["macOS", "OS X"]))
|
torrent["uploaded"] for torrent in response.json()
|
||||||
|
if any(keyword.lower() in torrent["name"].lower() for keyword in ["macOS", "OS X"])
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
active = False
|
|
||||||
print(f"Error accessing {qb_url['url']}: {e} | Code: {response.status_code}")
|
print(f"Error accessing {qb_url['url']}: {e} | Code: {response.status_code}")
|
||||||
|
|
||||||
return active, total_uploaded
|
return total_uploaded
|
||||||
|
|
||||||
def bytes_to_human_readable(num_bytes):
|
def bytes_to_human_readable(num_bytes):
|
||||||
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
||||||
|
|
@ -50,11 +49,11 @@ def update_readme(stats):
|
||||||
start_marker = "<!--- STATS_START --->"
|
start_marker = "<!--- STATS_START --->"
|
||||||
end_marker = "<!--- STATS_END --->"
|
end_marker = "<!--- STATS_END --->"
|
||||||
stats_table = f"""
|
stats_table = f"""
|
||||||
| Server | Active | Total Upload |
|
| Server | Total Upload |
|
||||||
|--------|--------|--------------|
|
|--------|--------------|
|
||||||
| Server1 | {stats['server1']['active']} | {stats['server1']['total_upload']} |
|
| Server1 | {stats['server1']['total_upload']} |
|
||||||
| Server2 | {stats['server2']['active']} | {stats['server2']['total_upload']} |
|
| Server2 | {stats['server2']['total_upload']} |
|
||||||
| **Combined** | - | {stats['combined_total_upload']} |
|
| **Combined** | {stats['combined_total_upload']} |
|
||||||
"""
|
"""
|
||||||
|
|
||||||
new_readme_content = readme_content.split(start_marker)[0] + start_marker + stats_table + end_marker + readme_content.split(end_marker)[1]
|
new_readme_content = readme_content.split(start_marker)[0] + start_marker + stats_table + end_marker + readme_content.split(end_marker)[1]
|
||||||
|
|
@ -62,18 +61,16 @@ def update_readme(stats):
|
||||||
with open(readme_path, "w") as file:
|
with open(readme_path, "w") as file:
|
||||||
file.write(new_readme_content)
|
file.write(new_readme_content)
|
||||||
|
|
||||||
server1_active, server1_total_upload = get_uploaded(qb_urls[0], qb_urls[0]["auth_type"])
|
server1_total_upload = get_uploaded(qb_urls[0], qb_urls[0]["auth_type"])
|
||||||
server2_active, server2_total_upload = get_uploaded(qb_urls[1], qb_urls[1]["auth_type"])
|
server2_total_upload = get_uploaded(qb_urls[1], qb_urls[1]["auth_type"])
|
||||||
|
|
||||||
combined_total_upload = server1_total_upload + server2_total_upload
|
combined_total_upload = server1_total_upload + server2_total_upload
|
||||||
|
|
||||||
stats = {
|
stats = {
|
||||||
"server1": {
|
"server1": {
|
||||||
"active": "Yes" if server1_active else "No",
|
|
||||||
"total_upload": bytes_to_human_readable(server1_total_upload)
|
"total_upload": bytes_to_human_readable(server1_total_upload)
|
||||||
},
|
},
|
||||||
"server2": {
|
"server2": {
|
||||||
"active": "Yes" if server2_active else "No",
|
|
||||||
"total_upload": bytes_to_human_readable(server2_total_upload)
|
"total_upload": bytes_to_human_readable(server2_total_upload)
|
||||||
},
|
},
|
||||||
"combined_total_upload": bytes_to_human_readable(combined_total_upload)
|
"combined_total_upload": bytes_to_human_readable(combined_total_upload)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue