The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,311 other followers

coinmon: In case you don’t want to install 61 packages [1] :)

Posted by jpluimers on 2017/12/04

via: [WayBack] Hacker News – coinmon: In case you don’t want to install 61 packages [1] :) and [WayBack] The curl + jq based approach to check Bitcoin prices looks a bit more attractive than using a node.js package with 61 dependencies, doesn’t it? Source:… – ThisIsWhyICode – Google+

Function to call curl from bash:

    $ coinmon() {
    >     curl "https://api.coinmarketcap.com/v1/ticker/?convert=$1" | jq ".[0] .price_$1"
    > }

    $ coinmon eur
    "6988.4723188"

Or in Python (from the same HackerNew thread): [Archive.is] https://www.pastery.net/jnscrh/

#!/usr/bin/env python3

from urllib.request import urlopen
from decimal import Decimal
import json

def print_coin(coin):
    print("{} ticker:".format(coin["name"]))
    print("Price: {:,} EUR".format(Decimal(coin["price_eur"])))
    print("Market cap: {:,} EUR".format(Decimal(coin["market_cap_eur"])))
    print()


r = urlopen("https://api.coinmarketcap.com/v1/ticker/?convert=eur")
coins = json.loads(r.read().decode("utf8"))

for coin in coins:
    if coin["id"] in ("bitcoin", "ethereum", "ripple", "monero"):
        print_coin(coin)

–jeroe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: