From 8c79e7fc3e37309955cf0eeb6a12797508f7a8a5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 3 Mar 2014 22:27:43 +0100 Subject: add weather to moderate example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/moderate | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'examples/moderate') diff --git a/examples/moderate b/examples/moderate index 1d7fc23..399afea 100644 --- a/examples/moderate +++ b/examples/moderate @@ -11,6 +11,7 @@ from plugins.network import Network from plugins.users import Users from plugins.pacman import Pacman from plugins.uname import Uname +from plugins.weather import Weather OUTPUT, YPOS, TOP = 0, 24, True @@ -155,16 +156,42 @@ def cpu(): return cpu +weather_last = '?' +weather_semaphore = threading.Semaphore() +def weather_update_(): + global weather_last + if weather_semaphore.acquire(blocking = False): + try: + weather_ = Weather('ESSA').temp + colour = '34' + if weather_ < -10: colour = '39;44' + if weather_ >= 18: colour = '39' + if weather_ >= 25: colour = '33' + if weather_ >= 30: colour = '31' + weather_ = '\033[%sm%.0f\033[0m°C' % (colour, weather_) + weather_last = weather_ + except: + if not weather_last.endswith('?'): + weather_last += '?' + weather_semaphore.release() +weather_update = Sometimes(lambda : async(weather_update_), 20 * 60 * 2) +def weather(): + rc = weather_last + weather_update() + return rc + + functions = [ Sometimes(lambda : clock_.read(), 1 * 2), lambda : time.time() % 1, Sometimes(users, 1 * 2), + weather, cpu, memory, network, Sometimes(uname, 30 * 60 * 2), ] -pattern = [ '%s │ %.2f │ %s }{ %s │ %s │ %s │ %s' +pattern = [ '%s │ %.2f │ %s │ %s }{ %s │ %s │ %s │ %s' ] -- cgit v1.2.3-70-g09d2