From 029c700d906706a7c6cc7901a2ed1c2f341e5419 Mon Sep 17 00:00:00 2001 From: Iordanis Fostiropoulos Date: Sun, 28 Oct 2018 17:03:57 -0700 Subject: [PATCH 1/2] Added cryptocurrency conversion --- hackr/converter.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 hackr/converter.py diff --git a/hackr/converter.py b/hackr/converter.py new file mode 100644 index 0000000..119be68 --- /dev/null +++ b/hackr/converter.py @@ -0,0 +1,14 @@ +import requests +import json + +""" + +Provides Pricing information on a crypto pair or currency pair, such as USD, BTC, ETH EUR + +""" +def cryptoPricePair(coinA, coinB): + try: + res = json.loads(requests.get('https://min-api.cryptocompare.com/data/price?fsym=%s&tsyms=%s'%(coinA.upper(),coinB.upper())).text) + return str(res[coinB.upper()]) + except Exception as _: + print 'Could not get live IP address' From 64bf6d0d3c204512292479e124f9d259cb676670 Mon Sep 17 00:00:00 2001 From: Iordanis Fostiropoulos Date: Sun, 18 Nov 2018 10:22:43 -0800 Subject: [PATCH 2/2] README for cryptocurrency converter and init --- README.rst | 10 +++++++++- hackr/__init__.py | 1 + hackr/converter.py | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 45dd686..8ce6177 100644 --- a/README.rst +++ b/README.rst @@ -123,7 +123,15 @@ Cryptography >>> d.sha1() hackr - + + +Cryptocurrencies + +.. code:: python + + >>> import hackr + >>> hackr.converter.cryptoPricePair('USD','BTC') + 0.0001785 Contribution Guidelines ----------------------- diff --git a/hackr/__init__.py b/hackr/__init__.py index e65a7f9..2d26055 100644 --- a/hackr/__init__.py +++ b/hackr/__init__.py @@ -9,3 +9,4 @@ from . import image from . import iptools from . import crypto +from . import converter diff --git a/hackr/converter.py b/hackr/converter.py index 119be68..340b688 100644 --- a/hackr/converter.py +++ b/hackr/converter.py @@ -8,7 +8,7 @@ """ def cryptoPricePair(coinA, coinB): try: - res = json.loads(requests.get('https://min-api.cryptocompare.com/data/price?fsym=%s&tsyms=%s'%(coinA.upper(),coinB.upper())).text) - return str(res[coinB.upper()]) + res = json.loads(requests.get('https://min-api.cryptocompare.com/data/price?fsym=%s&tsyms=%s'%(coinA.upper(),coinB.upper())).text) + return str(res[coinB.upper()]) except Exception as _: print 'Could not get live IP address'