power menu, redshift, polybar

This commit is contained in:
azpsen
2024-01-28 16:37:10 -06:00
parent 89516a6ce1
commit 319b44ecbd
307 changed files with 7642 additions and 5 deletions

View File

@@ -0,0 +1,27 @@
# Script: network-huawei-modem
Print stats from Huawei modem sticks. Such as signal levels, sms count and traffic bandwidth.
Tested with E3372h-320, but should work with others.
![network-huawei-modem](screenshots/1.png)
## Dependencies
* [`Salamek/huawei-lte-api`](https://github.com/Salamek/huawei-lte-api)
## Configuration
Just insert your modem ip and credentials into heading of script.
## Module
```ini
[module/network-huawei-modem]
type = custom/script
exec = ~/polybar-scripts/network-huawei-modem.py
interval = 5
```

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*- # PEP 263
from huawei_lte_api.Client import Client
from huawei_lte_api.Connection import Connection
# Configuration
host = '192.168.8.1'
username = 'admin'
password = ''
MODEM_URL = f"http://{username}:{password}@{host}/"
def scale_units(rate):
decimal_places = 2
for unit in ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps']:
if rate < 1000.0:
if unit == 'bps':
decimal_places = 0
break
rate /= 1000.0
return f"{rate:.{decimal_places}f}{unit}"
if __name__ == '__main__':
with Connection(MODEM_URL) as connection:
# This just simplifies access to separate API groups,
# you can use device = Device(connection) if you want
client = Client(connection)
signal = client.device.signal()
traffic = client.monitoring.traffic_statistics()
sms = client.sms.sms_count()
status = client.monitoring.status()
sms_unread = int(sms['LocalUnread'])
power = status['SignalIcon']
sinr = signal['sinr']
sms_icon = '' if sms_unread else ''
down = scale_units(int(traffic['CurrentDownloadRate']) * 8)
up = scale_units(int(traffic['CurrentUploadRate']) * 8)
result = f":{power} SINR:{sinr} {sms_icon}:{sms_unread}{down}{up}"
print(result)

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB