Init
This commit is contained in:
23
api/kuma.py
Normal file
23
api/kuma.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from uptime_kuma_api import UptimeKumaApi
|
||||
import json
|
||||
|
||||
class KumaAPI:
|
||||
def __init__(self, ip, password):
|
||||
self.api = UptimeKumaApi(ip)
|
||||
self.api.login('admin', password)
|
||||
|
||||
def get_status(self):
|
||||
monitors = self.api.get_monitors()
|
||||
|
||||
res = {}
|
||||
for monitor in monitors:
|
||||
id = monitor['id']
|
||||
status = self.api.get_monitor_status(id)
|
||||
res[id] = {
|
||||
"status": status,
|
||||
"name": monitor["name"],
|
||||
}
|
||||
|
||||
return res
|
||||
20
api/qbittorrent.py
Normal file
20
api/qbittorrent.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from qbittorrent import Client
|
||||
|
||||
# Replace with your qBittorrent Web UI credentials
|
||||
qb = Client('http://192.168.1.17:8112')
|
||||
qb.login('admin', 'tMHNjrJr7nhjyhJrYsahi4anq2h6LJ')
|
||||
|
||||
# Retrieve all active torrents
|
||||
torrents = qb.torrents(filter='downloading')
|
||||
|
||||
# Print details of each active torrent
|
||||
for torrent in torrents:
|
||||
print(f"Name: {torrent['name']}")
|
||||
print(f"State: {torrent['state']}")
|
||||
print(f"Progress: {torrent['progress'] * 100:.2f}%")
|
||||
print(f"Download Speed: {torrent['dlspeed'] / 1024:.2f} KB/s")
|
||||
print(f"Upload Speed: {torrent['upspeed'] / 1024:.2f} KB/s")
|
||||
print(f"Size: {torrent['size'] / (1024 * 1024):.2f} MB")
|
||||
print('-' * 40)
|
||||
27
api/torrent.py
Normal file
27
api/torrent.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from qbittorrent import Client
|
||||
|
||||
class TorrentApi:
|
||||
def __init__(self, ip, password, username='admin'):
|
||||
# Initialize the qBittorrent client
|
||||
self.qb = Client(ip)
|
||||
self.qb.login(username, password)
|
||||
|
||||
def get_torrents(self):
|
||||
return self.get_filtered_torrents('all')
|
||||
|
||||
def get_filtered_torrents(self, state):
|
||||
# Retrieve torrents filtered by the given state
|
||||
torrents = self.qb.torrents(filter=state)
|
||||
# Extract relevant information
|
||||
torrent_list = []
|
||||
for torrent in torrents:
|
||||
torrent_info = {
|
||||
'name': torrent['name'],
|
||||
'state': torrent['state'],
|
||||
'progress': torrent['progress'] * 100, # Convert to percentage
|
||||
'eta': torrent['eta']
|
||||
}
|
||||
torrent_list.append(torrent_info)
|
||||
return torrent_list
|
||||
Reference in New Issue
Block a user