fucking-great-advice added

This commit is contained in:
Von Random 2018-11-02 20:15:33 +03:00
parent 412f2de6b7
commit 05f83d818b
2 changed files with 22 additions and 1 deletions

21
plugins/fga.py Normal file
View file

@ -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

View file

@ -17,6 +17,6 @@ class PluginThread(plugins.PluginThreadCommon):
self.status['urgent'] = count >= self.conf['problem'] self.status['urgent'] = count >= self.conf['problem']
def main(self): 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(" -> ") updates = subprocess.getoutput('/usr/bin/pacman -Qu').count(" -> ")
self.format_status(updates) self.format_status(updates)