Skip to content

display IP address in sys_info.py #177

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions examples/sys_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def cpu_usage():
# load average, uptime
uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())
av1, av2, av3 = os.getloadavg()
return "Ld:%.1f %.1f %.1f Up: %s" \
return "Ld:%.1f %.1f %.1f Up:%s" \
% (av1, av2, av3, str(uptime).split('.')[0])


def mem_usage():
usage = psutil.virtual_memory()
return "Mem: %s %.0f%%" \
return "Mem: %s used %.0f%% avail" \
% (bytes2human(usage.used), 100 - usage.percent)


Expand All @@ -75,26 +75,36 @@ def disk_usage(dir):
% (bytes2human(usage.used), usage.percent)


def ipaddress(iface):
return "%s" % \
psutil.net_if_addrs()[iface][0][1]

def network(iface):
stat = psutil.net_io_counters(pernic=True)[iface]
return "%s: Tx%s, Rx%s" % \
(iface, bytes2human(stat.bytes_sent), bytes2human(stat.bytes_recv))
return "%s: Tx %s, Rx %s " % \
(iface, bytes2human(stat.bytes_sent), bytes2human(stat.bytes_recv))


def stats(device):
# use custom font
font_path = str(Path(__file__).resolve().parent.joinpath('fonts', 'C&C Red Alert [INET].ttf'))
font2 = ImageFont.truetype(font_path, 12)
font12 = ImageFont.truetype(font_path, 12)
font14 = ImageFont.truetype(font_path, 14)

with canvas(device) as draw:
draw.text((0, 0), cpu_usage(), font=font2, fill="white")
if device.width >= 132:
draw.text((0, 0), cpu_usage(), font=font12, fill="white")
else:
draw.text((0, 0), cpu_usage().replace(" days,","d"), font=font12, fill="white")

if device.height >= 32:
draw.text((0, 14), mem_usage(), font=font2, fill="white")
draw.text((0, 13), mem_usage(), font=font12, fill="white")

if device.height >= 64:
draw.text((0, 26), disk_usage('/'), font=font2, fill="white")
draw.text((0, 26), disk_usage('/'), font=font12, fill="white")
draw.text((58, 25), ipaddress('wlan0'), font=font14, fill="white")
try:
draw.text((0, 38), network('wlan0'), font=font2, fill="white")
draw.text((0, 39), network('wlan0'), font=font12, fill="white")
except KeyError:
# no wifi enabled/available
pass
Expand All @@ -112,3 +122,4 @@ def main():
main()
except KeyboardInterrupt:
pass

Loading