diff options
-rw-r--r-- | examples/moderate | 15 | ||||
-rw-r--r-- | src/plugins/chase.py | 56 |
2 files changed, 69 insertions, 2 deletions
diff --git a/examples/moderate b/examples/moderate index 399afea..e7407e5 100644 --- a/examples/moderate +++ b/examples/moderate @@ -12,6 +12,7 @@ from plugins.users import Users from plugins.pacman import Pacman from plugins.uname import Uname from plugins.weather import Weather +from plugins.chase import Chase OUTPUT, YPOS, TOP = 0, 24, True @@ -181,17 +182,27 @@ def weather(): return rc +chase_ = Chase() +chase_update = Sometimes(lambda : async(chase_.update), 2 * 60 * 60 * 2) +def chase(): + status = chase_.status + status = '39' if status is None else ('32' if status else '31') + chase_update() + return '\033[%smChase\033[0m' % status + + functions = [ Sometimes(lambda : clock_.read(), 1 * 2), lambda : time.time() % 1, Sometimes(users, 1 * 2), weather, + chase, cpu, memory, network, Sometimes(uname, 30 * 60 * 2), ] -pattern = [ '%s │ %.2f │ %s │ %s }{ %s │ %s │ %s │ %s' +pattern = [ '%s │ %.2f │ %s │ %s │ %s }{ %s │ %s │ %s │ %s' ] @@ -211,7 +222,7 @@ def redraw(): if semaphore.acquire(blocking = False): values = pattern % tuple([f() for f in functions]) bar.clear() - print(values.replace('\0', ' ' * 8)) + #print(values.replace('\0', ' ' * 8)) bar.draw_coloured_splitted_text(0, bar.width, 10, 0, 2, values) semaphore.release() return True diff --git a/src/plugins/chase.py b/src/plugins/chase.py new file mode 100644 index 0000000..d782ea9 --- /dev/null +++ b/src/plugins/chase.py @@ -0,0 +1,56 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +''' + +import sys +import subprocess + + +class Chase: + ''' + Does Chase have a job yet? + + @variable status:bool? Whether or not Chase have a job, `None` if information has not been fetched + ''' + + + def __init__(self): + ''' + Constructor + ''' + self.status = None + + + def update(self): + ''' + Update the information + + @return :bool Whether information could be fetched + ''' + command = ['wget', 'http://www.doeschasehaveajobyet.com', '-O', '-'] + proc = subprocess.Popen(command, stderr = sys.stderr, stdout = subprocess.PIPE) + page = proc.stdout.read() + proc.wait() + if proc.returncode == 0: + page = page.decode('utf-8', 'replace').split('\n') + page = filter(lambda line : line == 'NO', page) + page = filter(lambda line : not line == 'NOVEMBER', page) + self.status = len(list(page)) == 1 + return True + return False + |