Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uptime information (on linux) #448

Open
orzel opened this issue Jan 12, 2024 · 1 comment
Open

Add uptime information (on linux) #448

orzel opened this issue Jan 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@orzel
Copy link

orzel commented Jan 12, 2024

I want to display the uptime, which is quite a common information to display on such devices.
I tried by myself, adding stuff in library/sensors/sensors.py and library/stats.py, but I failed miserably. That sounds quite easy to do if you know the code better than I do.

I couldn't find any pythonish way of getting the current uptime, but this code does the trick on linux:

from datetime import timedelta
with open('/proc/uptime', 'r') as f: uptime_s = float(f.readline().split()[0])
uptime_string = str(timedelta(seconds=uptime_s))
@orzel orzel added the enhancement New feature or request label Jan 12, 2024
@NurNano
Copy link

NurNano commented Mar 28, 2024

I found an other solution.
You need the
pip3 install uptime
dependency.
Then u just can cast:

from uptime import uptime
import time
uptime()

It will give u the uptime in seconds.
Then u can change the code to

from uptime import uptime
import datetime

sec = uptime()
convert = str(datetime.timedelta(seconds = sec))
convert = convert.split(".")[0]  # entferne Millisekunden
print(convert)

and it will give you a output like "49 days, 16:47:16".

Would be happy if someone could build this in.
I've testet it on Windows and Debian with Python 3.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants