From 00d5087503e65af95b4854002b4d54fdbc80b072 Mon Sep 17 00:00:00 2001 From: Sheppy Date: Fri, 29 Sep 2017 02:49:38 +0200 Subject: [PATCH] Added IP --- herbstluftwm/hl_panel_content.py | 33 ++++++++------------------------ herbstluftwm/hl_status_deamon.py | 26 +++++++++++++++++-------- herbstluftwm/hl_utils.py | 2 +- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/herbstluftwm/hl_panel_content.py b/herbstluftwm/hl_panel_content.py index 15f9859..9f99fd8 100755 --- a/herbstluftwm/hl_panel_content.py +++ b/herbstluftwm/hl_panel_content.py @@ -86,6 +86,12 @@ def vpn(): tmp = ' '+tmp return tmp; +def ip(): + with open(hl_utils.hlpath("ip.log")) as f: + tmp = f.read() + tmp = ' '+tmp + return tmp; + def battery(): if hl_utils.is_laptop(): try: @@ -114,30 +120,7 @@ def battery(): return color_panel(str(e),RED) else: return "" + -def irc(): - if hl_utils.is_cip(): - ret_string = "IRC ERROR" - try: - fname = hl_utils.hlpath("irc.log") - tmp = [] - with open(fname) as f: - for l in f: - tmp+=[l] - if len(tmp) == 0: - return "" - msg = " ".join(tmp[-1].split(" ")[2:])[:50] - user = tmp[-1].split(" ")[1][:15] - if not "%push" in msg: - return "" - pattern = re.compile("\^+[fb]g[(]+#[0-9]+[)]+") - msg = re.sub(pattern,"",msg) - user = re.sub(pattern,"",user) - ret_string = "MSG FROM: "+user+"-> "+msg.rstrip('\n')+" - [ "+str(len(tmp))+" total ]" - return color_panel(ret_string,RED) - except(IOError): - pass - else: - return '' if __name__ == "__main__": - print(vpn(),guthaben(),battery(),sep='') + print(ip(),vpn(),guthaben(),battery(),sep='') diff --git a/herbstluftwm/hl_status_deamon.py b/herbstluftwm/hl_status_deamon.py index 5790392..d09cd24 100755 --- a/herbstluftwm/hl_status_deamon.py +++ b/herbstluftwm/hl_status_deamon.py @@ -4,12 +4,15 @@ import sys import time import sys import subprocess -from hl_panel_content import color_panel +from hl_panel_content import color_panel, get_color from hl_utils import error, is_cip, shexec, color_remove, hlpath, is_laptop +import re RED = 0xff0000 GREEN = 0x32CD32 YELLOW = 0xffff00 +BAT_COLOR_OFFSET = 10 + #Druckerguthaben def pr_acct_status(): @@ -43,7 +46,7 @@ def vpn_status(): def battery(): try: - bat = hl_utils.shexec("acpi -b") + bat = shexec("acpi -b") if bat == '': return color_panel("BATTERY FAILURE",RED) bat = re.compile(r'Battery [0-9]+: ').sub('',bat) @@ -69,21 +72,28 @@ def battery(): def battery_status(): if is_laptop: - with open(hlpatch("battery.log")) as g: + with open(hlpath("battery.log"),'w') as g: g.write(battery()) +def ip_status(): + with open(hlpath("ip.log"),'w') as g: + p="Public IP: " + try: + tmp=color_panel(p+shexec("wget --timeout=3 -O- --quiet https://atlantishq.de/ipcheck"),GREEN) + except: + tmp=color_panel("Offline",RED) + g.write(tmp) + if __name__ == '__main__': #print('"'+sys.argv[-1]+'"') - if sys.argv[-1]=='--refresh': - vpn_status() - pr_acct_status() - battery() - sys.exit() while(True): vpn_status() pr_acct_status() battery_status() + ip_status() + if sys.argv[-1]=='--refresh': + break time.sleep(30) diff --git a/herbstluftwm/hl_utils.py b/herbstluftwm/hl_utils.py index f134834..12ab9bc 100755 --- a/herbstluftwm/hl_utils.py +++ b/herbstluftwm/hl_utils.py @@ -13,7 +13,7 @@ def color_remove(s): return re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]').sub('',s) def shexec(s): - return subprocess.check_output(shlex.split(s),shell=True).decode() + return subprocess.check_output(shlex.split(s),shell=False).decode() def is_cip(): u = os.uname()