Skip to content

Instantly share code, notes, and snippets.

@helb
Last active January 3, 2018 22:09
Show Gist options
  • Select an option

  • Save helb/86a7bf0c328255ee9dba97890fd5da0e to your computer and use it in GitHub Desktop.

Select an option

Save helb/86a7bf0c328255ee9dba97890fd5da0e to your computer and use it in GitHub Desktop.

Revisions

  1. helb revised this gist Jan 3, 2018. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions butter.py
    Original 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(",", "."))
    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()
  2. helb revised this gist Jan 3, 2018. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions butter.py
    Original 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")
    price = html.findAll("p", {"class": "cena"})[0]
    price = "".join([t for t in price.contents if type(t) == element.NavigableString])
    return float(price.replace(",", "."))
    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()
  3. helb renamed this gist Jan 3, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. helb revised this gist Jan 3, 2018. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions README.md
    Original 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
    ```
  5. helb created this gist Jan 3, 2018.
    42 changes: 42 additions & 0 deletions butter.py
    Original 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))