From 35a2a082c6119fd4437b8a17a597cb2bbaf34ca4 Mon Sep 17 00:00:00 2001 From: Stefan Weijers Date: Sun, 25 Jul 2021 18:59:09 +0200 Subject: [PATCH] Add time/start script and add fancy name to config --- config.py | 3 +++ time.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 time.py diff --git a/config.py b/config.py index 38dc282..3b44b39 100644 --- a/config.py +++ b/config.py @@ -11,3 +11,6 @@ class env: # 'service name' : 'display name' 'gdm': 'GNOME Display Manager' } + name = '███████╗██████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗██╗ ██╗██╗██╗\n██╔════╝██╔══██╗██╔═══██╗██╔═══██╗██╔══██╗██║ ██╔╝██║ ██║██║██║\n███████╗██████╔╝██║ ██║██║ ██║██████╔╝█████╔╝ ██║ ██║██║██║\n╚════██║██╔═══╝ ██║ ██║██║ ██║██╔══██╗██╔═██╗ ██║ ██║██║██║\n███████║██║ ╚██████╔╝╚██████╔╝██║ ██║██║ ██╗╚██████╔╝██║███████╗\n╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝╚══════╝' + + diff --git a/time.py b/time.py new file mode 100644 index 0000000..a57a741 --- /dev/null +++ b/time.py @@ -0,0 +1,44 @@ +import os +from config import bcolors,env + +# Sample output: 18:30:40 up 89 days, 19:23, 4 users, load average: etc +# Sample output: 18:42:20 up 5:56, 1 user, load average: 0.64, 0.62, 0.69 +def filter(lsinp): + res = [] + for elem in lsinp: + if ':' in elem: res.append(elem) + return res + +def parseDays(inp): + tmp = inp.split('user') # should be ['18:30:40 up 89 days, 19:23, 4 ', 's load average etc'] + tmp2 = tmp[0].split(',') + tmpmin = tmp2[1].split(':') + hours = tmpmin[0].strip() + minutes = tmpmin[1].strip() + tmpday = tmp2[0].split(' ') + days = tmpday[2].strip() + return (days,hours,minutes) + +def parseNoDays(inp): + tmp = inp.split(' ') + tmp = filter(tmp) + tmpmin = tmp[1].split(':') + hours = tmpmin[0].strip() + minutes = tmpmin[1].strip(',') + return (hours, minutes) + +def prettyPrint(value, typeofvalue): return bcolors.EMPTY + value + ' ' + bcolors.RESET + typeofvalue + +time = os.popen('uptime').read() # Execute command on system + +print(bcolors.EMPTY + env.name + bcolors.RESET) +print('Server has been running for:') +if 'days' in time: + days, hours, minutes = parseDays(time) + print('[' + prettyPrint(days, 'days') + ', ' + prettyPrint(hours, 'hours') + ' and ' + prettyPrint(minutes, 'minutes') + ']') +else: + hours, minutes = parseNoDays(time) + print('[' + prettyPrint(hours, 'hours') + ' and ' + prettyPrint(minutes, 'minutes') + ']') + + +