From 975027820f259c82fc65866c0c03850cc236189a Mon Sep 17 00:00:00 2001 From: Antonis Karamitros Date: Thu, 7 Sep 2017 12:54:29 +0100 Subject: [PATCH 1/4] Add an fx module to track GBP/EUR and GBP/USD --- bumblebee/modules/fx.py | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 bumblebee/modules/fx.py diff --git a/bumblebee/modules/fx.py b/bumblebee/modules/fx.py new file mode 100644 index 0000000..30aace1 --- /dev/null +++ b/bumblebee/modules/fx.py @@ -0,0 +1,51 @@ +# -*- coding: UTF-8 -*- +# pylint: disable=C0111,R0903 + +import bumblebee.input +import bumblebee.output +import bumblebee.engine +import json +import time +try: + import requests + from requests.exceptions import RequestException +except ImportError: + pass + +class Module(bumblebee.engine.Module): + def __init__(self, engine, config): + super(Module, self).__init__(engine, config, + bumblebee.output.Widget(full_text=self.price) + ) + self._price = "-" + self._interval = int(self.parameter("interval", "1")) + self._nextcheck = 0 + self._valid = False + + def price(self, widget): + if not self._valid: + return u"?" + return self._price + + def update(self, widgets): + timestamp = int(time.time()) + if self._nextcheck < int(time.time()): + try: + self._nextcheck = int(time.time()) + self._interval*60 + price_url = "http://api.fixer.io/latest?symbols=USD,EUR&base=GBP" + try: + price_json = json.loads( requests.get(price_url).text ) + gbpeur = str(price_json['rates']['EUR']) + gbpusd = str(price_json['rates']['USD']) + except ValueError: + gbpeur = "-" + gbpusd = "-" + + self._price = "£/€ " + gbpeur + " | £/$ " + gbpusd + self._valid = True + except RequestException: + self._price = "£/€ - | £/$ -" + self._valid = True + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 + From 86de505cdada17ddf507b85ea5dc536b02d86b54 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 7 Sep 2017 16:10:22 +0200 Subject: [PATCH 2/4] [modules] rename fx to currency see #169 --- bumblebee/modules/{fx.py => currency.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bumblebee/modules/{fx.py => currency.py} (100%) diff --git a/bumblebee/modules/fx.py b/bumblebee/modules/currency.py similarity index 100% rename from bumblebee/modules/fx.py rename to bumblebee/modules/currency.py From 4ebce517ccb14370adfc9c5aacb3858b9002807d Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 7 Sep 2017 16:16:35 +0200 Subject: [PATCH 3/4] [modules/currency] Use unicode strings see #169 --- bumblebee/modules/currency.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/currency.py b/bumblebee/modules/currency.py index 30aace1..580c91d 100644 --- a/bumblebee/modules/currency.py +++ b/bumblebee/modules/currency.py @@ -41,10 +41,10 @@ class Module(bumblebee.engine.Module): gbpeur = "-" gbpusd = "-" - self._price = "£/€ " + gbpeur + " | £/$ " + gbpusd + self._price = u"£/€ " + gbpeur + u" | £/$ " + gbpusd self._valid = True except RequestException: - self._price = "£/€ - | £/$ -" + self._price = u"£/€ - | £/$ -" self._valid = True # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 From f7555f8d6b9836ea9668f29031d2727422ed5052 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 7 Sep 2017 16:19:37 +0200 Subject: [PATCH 4/4] [modules/currency] Add documentation and screenshot see #169 --- bumblebee/modules/currency.py | 8 ++++++++ screenshots/currency.png | Bin 0 -> 2561 bytes 2 files changed, 8 insertions(+) create mode 100644 screenshots/currency.png diff --git a/bumblebee/modules/currency.py b/bumblebee/modules/currency.py index 580c91d..79be8e1 100644 --- a/bumblebee/modules/currency.py +++ b/bumblebee/modules/currency.py @@ -1,6 +1,14 @@ # -*- coding: UTF-8 -*- # pylint: disable=C0111,R0903 +"""Displays currency exchange rates. Currently, displays currency between GBP and USD/EUR only. + +Requires the following python packages: + * requests + +Parameters: + * currency.interval: Interval in minutes between updates, default is 1. + import bumblebee.input import bumblebee.output import bumblebee.engine diff --git a/screenshots/currency.png b/screenshots/currency.png new file mode 100644 index 0000000000000000000000000000000000000000..ffcc549fa7fb2f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