mirror of
https://gitlab.sectorq.eu/jaydee/python.git
synced 2025-12-14 10:44:52 +01:00
asa
This commit is contained in:
56
mqtt_srv.py
56
mqtt_srv.py
@@ -27,43 +27,49 @@ if curos == "Windows":
|
|||||||
import winreg
|
import winreg
|
||||||
def uptime():
|
def uptime():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open( "/proc/uptime" )
|
f = open( "/proc/uptime" )
|
||||||
contents = f.read().split()
|
contents = f.read().split()
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
except:
|
||||||
return "Cannot open uptime file: /proc/uptime"
|
return "Cannot open uptime file: /proc/uptime"
|
||||||
|
|
||||||
total_seconds = float(contents[0])
|
total_seconds = float(contents[0])
|
||||||
|
|
||||||
# Helper vars:
|
# Helper vars:
|
||||||
MINUTE = 60
|
MINUTE = 60
|
||||||
HOUR = MINUTE * 60
|
HOUR = MINUTE * 60
|
||||||
DAY = HOUR * 24
|
DAY = HOUR * 24
|
||||||
|
|
||||||
# Get the days, hours, etc:
|
# Get the days, hours, etc:
|
||||||
days = int( total_seconds / DAY )
|
days = int( total_seconds / DAY )
|
||||||
hours = int( ( total_seconds % DAY ) / HOUR )
|
hours = int( ( total_seconds % DAY ) / HOUR )
|
||||||
minutes = int( ( total_seconds % HOUR ) / MINUTE )
|
minutes = int( ( total_seconds % HOUR ) / MINUTE )
|
||||||
seconds = int( total_seconds % MINUTE )
|
seconds = int( total_seconds % MINUTE )
|
||||||
|
|
||||||
# Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
|
# Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
|
||||||
string = ""
|
string = ""
|
||||||
# if days > 0:
|
# if days > 0:
|
||||||
# string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
|
# string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
|
||||||
# if len(string) > 0 or hours > 0:
|
# if len(string) > 0 or hours > 0:
|
||||||
# string += str(hours) + " " + (hours == 1 and "h" or "h" ) + ", "
|
# string += str(hours) + " " + (hours == 1 and "h" or "h" ) + ", "
|
||||||
# if len(string) > 0 or minutes > 0:
|
# if len(string) > 0 or minutes > 0:
|
||||||
# string += str(minutes) + " " + (minutes == 1 and "m" or "m" ) + ", "
|
# string += str(minutes) + " " + (minutes == 1 and "m" or "m" ) + ", "
|
||||||
if days > 0:
|
if days > 0:
|
||||||
string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
|
string += str(days) + " " + (days == 1 and "d" or "d" ) + ", "
|
||||||
if len(string) > 0 or hours > 0:
|
if len(string) > 0 or hours > 0:
|
||||||
string += str(hours) + ":"
|
if hours < 10:
|
||||||
if len(string) > 0 or minutes > 0:
|
hours = "0{}".format(hours)
|
||||||
string += str(minutes) + ":"
|
string += str(hours) + ":"
|
||||||
string += str(seconds)
|
if len(string) > 0 or minutes > 0:
|
||||||
|
if minutes < 10:
|
||||||
|
minutes = "0{}".format(minutes)
|
||||||
|
string += str(minutes) + ":"
|
||||||
|
|
||||||
return string;
|
if seconds < 10:
|
||||||
|
seconds = "0{}".format(seconds)
|
||||||
|
string += str(seconds)
|
||||||
|
return string;
|
||||||
|
|
||||||
def writeLog(msg, svr="INFO"):
|
def writeLog(msg, svr="INFO"):
|
||||||
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
@@ -319,7 +325,7 @@ IP = get_ip()
|
|||||||
print("OS : " + curos)
|
print("OS : " + curos)
|
||||||
writeLog("OS : " + curos)
|
writeLog("OS : " + curos)
|
||||||
if curos != "Windows":
|
if curos != "Windows":
|
||||||
import autorandr
|
import autorandr
|
||||||
else:
|
else:
|
||||||
import winreg
|
import winreg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user