Last active
January 3, 2018 22:09
-
-
Save helb/86a7bf0c328255ee9dba97890fd5da0e to your computer and use it in GitHub Desktop.
Revisions
-
helb revised this gist
Jan 3, 2018 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,14 +11,14 @@ butter_default_price = 30.00 def butter_price(): result = requests.get(butter_url) html = BeautifulSoup(result.content, "html5lib") if len(html.findAll("p", {"class": "warningfail"})) > 0: return butter_default_price else: price = html.findAll("p", {"class": "cena"})[0] price = "".join([t for t in price.contents if type(t) == element.NavigableString]) return float(price.replace(",", ".")) def usd_to_czk(): result = requests.get(fiat_url).json() -
helb revised this gist
Jan 3, 2018 . 1 changed file with 9 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,13 +8,17 @@ butter_url = "https://www.akcniceny.cz/zbozi/mlecne-vyrobky/masla/" bitgup_url = "https://bitgup.com/view_currency/" fiat_url = "https://api.fixer.io/latest?symbols=CZK&base=USD" butter_default_price = 30.00 def butter_price(): result = requests.get(butter_url) html = BeautifulSoup(result.content, "html5lib") if len(html.findAll("p", {"class": "warningfail"})) > 0: return butter_default_price else: price = html.findAll("p", {"class": "cena"})[0] price = "".join([t for t in price.contents if type(t) == element.NavigableString]) return float(price.replace(",", ".")) def usd_to_czk(): result = requests.get(fiat_url).json() -
helb renamed this gist
Jan 3, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
helb revised this gist
Jan 3, 2018 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ ``` $ ./butter.py BTC ETH LTC XRP ORE BCN SC DOGE BTC: 11112.06 ETH: 678.30 LTC: 178.65 XRP: 2.12 ORE: 10.80 BCN: 0.00 SC: 0.02 DOGE: 0.01 ``` -
helb created this gist
Jan 3, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #!/usr/bin/env python from bs4 import BeautifulSoup, element import requests import re from sys import argv from decimal import Decimal butter_url = "https://www.akcniceny.cz/zbozi/mlecne-vyrobky/masla/" bitgup_url = "https://bitgup.com/view_currency/" fiat_url = "https://api.fixer.io/latest?symbols=CZK&base=USD" def butter_price(): result = requests.get(butter_url) html = BeautifulSoup(result.content, "html5lib") price = html.findAll("p", {"class": "cena"})[0] price = "".join([t for t in price.contents if type(t) == element.NavigableString]) return float(price.replace(",", ".")) def usd_to_czk(): result = requests.get(fiat_url).json() return float(result["rates"]["CZK"]) def crypto_price(code): result = requests.get(f"{bitgup_url}/{code}/") html = BeautifulSoup(result.content, "html5lib") price = html.findAll("div", {"class": "price"})[0].text price = re.sub(r"[\s\$]+", "", price) return float(price) def crypto_to_butter(code, butter, czk): return crypto_price(code) * czk / butter def butters(code): amount = crypto_to_butter(code, butter, czk) return f"{code}:{' ' * (6 - len(code))}{round(Decimal(amount), 2)}" butter = butter_price() czk = usd_to_czk() if len(argv) > 1: for coin in argv[1:]: print(butters(coin))