From 05f83d818b69531a810600d9e9cbe6799bdb96b9 Mon Sep 17 00:00:00 2001 From: Von Random Date: Fri, 2 Nov 2018 20:15:33 +0300 Subject: [PATCH] fucking-great-advice added --- plugins/fga.py | 21 +++++++++++++++++++++ plugins/pacman.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 plugins/fga.py diff --git a/plugins/fga.py b/plugins/fga.py new file mode 100644 index 0000000..ccda9d5 --- /dev/null +++ b/plugins/fga.py @@ -0,0 +1,21 @@ +# TODO: tidy up the fucking code +import plugins +import requests + + +URI = 'http://fucking-great-advice.ru/api/random' +class PluginThread(plugins.PluginThreadCommon): + def __init__(self, config): + defaults = {'freq': 120} + super(PluginThread, self).__init__(config, defaults) + + + def main(self): + try: + req = requests.get(URI, timeout=2) + advice = req.json()['text'] if req.status_code == 200 else 'N/A' + except requests.exceptions.Timeout: + advice = 'N/A (timeout)' + except requests.exceptions.ConnectionError: + advice = 'N/A (offline)' + self.status['full_text'] = advice diff --git a/plugins/pacman.py b/plugins/pacman.py index 853bb6b..7a9586c 100644 --- a/plugins/pacman.py +++ b/plugins/pacman.py @@ -17,6 +17,6 @@ class PluginThread(plugins.PluginThreadCommon): self.status['urgent'] = count >= self.conf['problem'] def main(self): - # TODO: this is an ugly hack, fix it with subprocess.Popen asap + # TODO: this is an ugly hack, fix it with subprocess.Popen someday updates = subprocess.getoutput('/usr/bin/pacman -Qu').count(" -> ") self.format_status(updates)