updated ping.py
This commit is contained in:
parent
0f72583f31
commit
da44d56fa8
@ -1,4 +1,5 @@
|
||||
from requests import get
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
|
||||
class Platform:
|
||||
@ -8,16 +9,13 @@ class Platform:
|
||||
self.__dict__[key] = value
|
||||
|
||||
def process(self):
|
||||
try:
|
||||
value = get(self.resource)
|
||||
except Exception:
|
||||
icon_class = "theme-failure-text"
|
||||
param = "-n" if platform.system().lower() == "windows" else "-c"
|
||||
command = ["ping", param, "1", self.resource]
|
||||
up = subprocess.call(command) == 0
|
||||
|
||||
if 599 >= value.status_code >= 400:
|
||||
icon_class = "theme-failure-text"
|
||||
if 399 >= value.status_code >= 300:
|
||||
icon_class = "theme-warning-text"
|
||||
if 299 >= value.status_code >= 100:
|
||||
if up is True:
|
||||
icon_class = "theme-success-text"
|
||||
else:
|
||||
icon_class = "theme-failure-text"
|
||||
|
||||
return f"<i class='material-icons right {icon_class}'>fiber_manual_record </i>"
|
||||
|
@ -6,6 +6,7 @@ import transmissionrpc
|
||||
# from pprint import PrettyPrinter
|
||||
# pp = PrettyPrinter()
|
||||
|
||||
|
||||
class Platform:
|
||||
def __init__(self, *args, **kwargs):
|
||||
# parse the user's options from the config entries
|
||||
@ -15,20 +16,23 @@ class Platform:
|
||||
if not hasattr(self, "port"):
|
||||
self.port = 9091
|
||||
if not hasattr(self, "host"):
|
||||
self.host = 'localhost'
|
||||
self.host = "localhost"
|
||||
|
||||
self.tc = transmissionrpc.Client(self.host, port=self.port, user=self.user, password=self.password)
|
||||
self.tc = transmissionrpc.Client(
|
||||
self.host, port=self.port, user=self.user, password=self.password
|
||||
)
|
||||
|
||||
def process(self):
|
||||
|
||||
torrents = len(self.tc.get_torrents())
|
||||
data = {}
|
||||
for key, field in self.tc.session_stats().__dict__['_fields'].items():
|
||||
for key, field in self.tc.session_stats().__dict__["_fields"].items():
|
||||
data[key] = field.value
|
||||
# pp.pprint (data)
|
||||
|
||||
value_template = render_template_string(self.value_template, **data)
|
||||
return value_template
|
||||
|
||||
|
||||
# Testing
|
||||
# test = Platform(host='192.168.1.19', user='', password='').process()
|
||||
|
Loading…
x
Reference in New Issue
Block a user