#!/usr/bin/env python3

import json

import http.client as http

# curl https://api.coingecko.com/api/v3/coins/list
COINS = [
    # [id,      symbol]
    ["bitcoin", "BTC"],
    ["monero",  "XMR"],
]
CURRENCY = "eur"
FORMAT = "{coin}=€{price:.0f}"


def main():
    coin_ids = ",".join([coin[0] for coin in COINS])
    url = "api.coingecko.com"
    path = f"/api/v3/simple/price?ids={coin_ids}&vs_currencies={CURRENCY}"

    client = http.HTTPSConnection(url)
    client.request("GET", path)

    # {'bitcoin': {'usd': 69420}}
    prices = json.loads(client.getresponse().read())

    print(
        *[
            FORMAT.format(coin=coin[1], price=prices[coin[0]][CURRENCY])
            for coin in COINS
        ]
    )


if __name__ == "__main__":
    main()
