Compare commits

..

7 Commits

Author SHA1 Message Date
071ea6e4ad Обновить dwmbar 2024-12-10 03:19:40 +08:00
0e99ff770b Fix colors 2024-10-27 20:46:50 +05:00
b893d85525 Remove useless out 2024-05-31 20:35:45 +05:00
580a50f296 Update code for two status (third line in my dwm lost) 2024-05-31 20:34:28 +05:00
27add6597a Change some conf 2024-05-30 11:02:35 +05:00
0d0d7d0e4a Add defolt layout (no color) 2024-02-24 13:39:41 +05:00
b9ba514154 Del useless imports 2024-02-24 13:24:17 +05:00

200
dwmbar
View File

@ -6,35 +6,34 @@ import signal
import psutil
import alsaaudio
import requests
from subprocess import run, check_output
from Xlib import X, display, Xutil
from subprocess import run
from datetime import datetime
DD = ';'
DELIM = ' '
COLOR = True
def shutdown():
for task in asyncio.Task.all_tasks():
if task is not asyncio.tasks.Task.current_task():
task.cancel()
print("Shutting down...")
loop.stop()
async def dwmbar():
global bl, br
global DD
await asyncio.sleep(1)
while True:
bar = f"{status()}{DD}{bl}{DD}{br}"
bar = f"{status()}{DD}{extrabar()}"
# print(bar.encode('utf-8'))
# print(br)
# print(bar)
run(["xprop", "-root", "-set", "WM_NAME", bar], check=True)
await asyncio.sleep(0.1)
net = ram = cpu = gpu = wlan = disk = vol = lang = dat = tim = currates = weather = 0
def status():
global DELIM, net, ram, cpu, gpu, wlan, disk, vol, lang, dat, tim
@ -56,42 +55,47 @@ def status():
return ''
async def bl():
global bl
def extrabar():
global DELIM, currates, weather, COLOR
try:
bar = [
weather,
# currates
]
return DELIM.join(bar)
except:
return ''
async def currates():
global DELIM, currates, COLOR
COLOR1='#AAAAAA'
COLOR2='#444444'
while True:
curs = []
curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=XMRUSDT').json()['lastPrice']):.2f}"])
curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=BTCUSDT').json()['lastPrice']):.2f}"])
curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=LTCUSDT').json()['lastPrice']):.2f}"])
curs.append(['Ð', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=DOGEUSDT').json()['lastPrice']):.2f}"])
curs.append(['$', f"{float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTRUB').json()['lastPrice']):.2f} RUB"])
try:
curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=BTCUSDT').json()['lastPrice']):.2f}"])
# curs.append(['', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=LTCUSDT').json()['lastPrice']):.2f}"])
# curs.append(['Ð', f"${float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=DOGEUSDT').json()['lastPrice']):.2f}"])
curs.append(['',
f"""{
float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTRUB').json()['lastPrice']) /
float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTTRY').json()['lastPrice'])
:.2f} RUB"""
])
curs.append(['₴',
f"""{
float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTRUB').json()['lastPrice']) /
float(requests.get('https://api.binance.com/api/v3/ticker/24hr?symbol=USDTUAH').json()['lastPrice'])
:.2f} RUB"""
])
if COLOR:
row = list(map(lambda x: f'^b{COLOR1}^^c{COLOR2}^ {x[0]} ^c{COLOR1}^^b{COLOR2}^ {x[1]} ^d^', curs))
else:
row = list(map(lambda x: f'[{x[0]} | {x[1]}]', curs))
row = list(map(lambda x: f'^b{COLOR1}^^c{COLOR2}^ {x[0]} ^c{COLOR1}^^b{COLOR2}^ {x[1]} ^d^', curs))
bl = DELIM.join(row)
currates = DELIM.join(row)
except:
pass
await asyncio.sleep(60 * 10)
async def br():
global br
async def weather():
global weather, COLOR
COLOR1='#AAAAAA'
COLOR2='#444444'
@ -99,17 +103,23 @@ async def br():
CITY='Tyumen'
while True:
i = requests.get(f"https://wttr.in/{CITY}?format=%c").text.strip() #.encode('utf-8')[0:3].decode('utf-8')
t = requests.get(f"https://wttr.in/{CITY}?format=%t").text.strip()
w = requests.get(f"https://wttr.in/{CITY}?format=j2").json()['current_condition'][0]['windspeedKmph'].strip()
try:
i = requests.get(f"https://wttr.in/{CITY}?format=%c").text.strip() #.encode('utf-8')[0:3].decode('utf-8')
t = requests.get(f"https://wttr.in/{CITY}?format=%t").text.strip()
w = requests.get(f"https://wttr.in/{CITY}?format=j2").json()['current_condition'][0]['windspeedKmph'].strip()
br = f"^b{COLOR2}^^c{COLOR1}^ {w} km/h ^b{COLOR1}^^c{COLOR2}^ {i} ^c{COLOR1}^^b{COLOR2}^ {t} ^d^"
if COLOR:
weather = f"^b{COLOR2}^^c{COLOR1}^ {w} km/h ^b{COLOR1}^^c{COLOR2}^ {i} ^c{COLOR1}^^b{COLOR2}^ {t} ^d^"
else:
weather = f"[{w} km/h | {i} | {t}]"
except:
pass
await asyncio.sleep(60 * 30)
async def net():
global net
global net, COLOR
COLOR1='#FF9B00'
COLOR2='#A16200'
@ -127,12 +137,16 @@ async def net():
orecv = recv
osent = sent
net = f'^c{COLOR1}^^b{COLOR2}^ {inb} ^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {outb} ^d^'
if COLOR:
net = f'^c{COLOR1}^^b{COLOR2}^ {inb} ^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {outb} ^d^'
else:
net = f'[{inb} |  | {outb}]'
await asyncio.sleep(1)
async def ram():
global ram
global ram, COLOR
COLOR1='#C700FF'
COLOR2='#590073'
@ -141,38 +155,50 @@ async def ram():
ramt = psutil.virtual_memory().total / 1024 / 1024 / 1024
ramu = psutil.virtual_memory().used / 1024 / 1024 / 1024
ram = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {ramu:0.1f}/{ramt:0.1f}G ^d^'
if COLOR:
ram = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {ramu:0.1f}/{ramt:0.1f}G ^d^'
else:
ram = f'[ | {ramu:0.1f}/{ramt:0.1f}G]'
await asyncio.sleep(1)
async def cpu():
global cpu
global cpu, COLOR
COLOR1='#990057'
COLOR2='#FF00B2'
COLOR1='#FF00B2'
COLOR2='#990057'
while True:
load = psutil.cpu_percent()
cpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {load:0.0f}% ^d^'
if COLOR:
cpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {load:0.0f}% ^d^'
else:
cpu = f'[ | {load:0.0f}%]'
await asyncio.sleep(1)
async def gpu():
global gpu
global gpu, COLOR
COLOR1='#990057'
COLOR2='#FF00B2'
COLOR1='#FF00B2'
COLOR2='#990057'
while True:
load = open('/sys/class/drm/card0/device/gpu_busy_percent').read().strip()
load = open('/sys/class/drm/card1/device/gpu_busy_percent').read().strip()
if COLOR:
gpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {load}% ^d^'
else:
gpu = f'[ | {load}%]'
gpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {load}% ^d^'
await asyncio.sleep(1)
async def wlan():
global cpu
global cpu, COLOR
COLOR1='#009CFF'
COLOR2='#005083'
@ -181,12 +207,16 @@ async def wlan():
c = psutil.cpu_percent()
i = ''
cpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {c:0.0f}% ^d^'
if COLOR:
cpu = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {c:0.0f}% ^d^'
else:
cpu = f'[ | {c:0.0f}%]'
await asyncio.sleep(1)
async def disk():
global disk
global disk, COLOR
COLOR1='#00FF90'
COLOR2='#00A45D'
@ -195,12 +225,16 @@ async def disk():
f = psutil.disk_usage('/').free / 1024 / 1024 / 1024
t = psutil.disk_usage('/').total / 1024 / 1024 / 1024
disk = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {f:0.0f}/{t:0.0f}G ^d^'
if COLOR:
disk = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {f:0.0f}/{t:0.0f}G ^d^'
else:
disk = f'[ | {f:0.0f}/{t:0.0f}G]'
await asyncio.sleep(3)
async def vol():
global vol
global vol, COLOR
COLOR1='#FF0000'
COLOR2='#700000'
@ -220,12 +254,16 @@ async def vol():
if alsaaudio.Mixer().getmute()[0]:
i = ''
vol = f'^b{COLOR1}^^c{COLOR2}^ {i} ^c{COLOR1}^^b{COLOR2}^ {v}% ^d^'
if COLOR:
vol = f'^b{COLOR1}^^c{COLOR2}^ {i} ^c{COLOR1}^^b{COLOR2}^ {v}% ^d^'
else:
vol = f'[{i} | {v}%]'
await asyncio.sleep(1)
async def lang():
global lang
global lang, COLOR
COLOR1='#FF5800'
COLOR2='#973400'
@ -233,12 +271,16 @@ async def lang():
while True:
l = run(["xkblayout-state", "print", "%s"], check=True, capture_output=True, text=True).stdout
lang = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {l} ^d^'
if COLOR:
lang = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {l} ^d^'
else:
lang = f'[ | {l}]'
await asyncio.sleep(0.1)
async def tim():
global tim
global tim, COLOR
COLOR1='#00E9FF'
COLOR2='#008592'
@ -246,12 +288,16 @@ async def tim():
while True:
t = datetime.now().strftime("%H:%M:%S")
tim = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {t} ^d^'
if COLOR:
tim = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {t} ^d^'
else:
tim = f'[ | {t}]'
await asyncio.sleep(1)
async def dat():
global dat
global dat, COLOR
COLOR1='#17FF00'
COLOR2='#0EA100'
@ -259,15 +305,15 @@ async def dat():
while True:
d = datetime.now().strftime("%d.%m.%y")
dat = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {d} ^d^'
if COLOR:
dat = f'^b{COLOR1}^^c{COLOR2}^  ^c{COLOR1}^^b{COLOR2}^ {d} ^d^'
else:
dat = f'[ | {d}]'
await asyncio.sleep(1)
if __name__ == '__main__':
signal.signal(signal.SIGINT, lambda n, f: shutdown())
loop = asyncio.get_event_loop()
main_task = asyncio.wait([
async def main():
await asyncio.gather(
dwmbar(),
net(),
ram(),
@ -278,12 +324,20 @@ if __name__ == '__main__':
lang(),
dat(),
tim(),
bl(),
br()
])
# currates(),
weather()
)
if __name__ == '__main__':
signal.signal(signal.SIGINT, lambda n, f: shutdown())
loop = asyncio.get_event_loop()
main_task = asyncio.ensure_future(main())
try:
loop.run_until_complete(main_task)
except asyncio.CancelledError:
loop.run_until_complete(main_task)
loop.close()
except KeyboardInterrupt:
print("KeyboardInterrupt: Stopping the event loop...")
finally:
loop.close()