Skip to content

Instantly share code, notes, and snippets.

@saifazmi
Last active December 13, 2017 00:20
Show Gist options
  • Save saifazmi/14da024b891cf9f477d39036e1d05d4d to your computer and use it in GitHub Desktop.
Save saifazmi/14da024b891cf9f477d39036e1d05d4d to your computer and use it in GitHub Desktop.
A simple Bitcoin price checker using coindesks api
#!/usr/bin/python
import json
import requests
URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
response = requests.get(URL)
jsonResponse = json.loads(response.text)
updated = jsonResponse.get("time").get("updateduk")
valBTC = jsonResponse.get("bpi")
rateUSD = valBTC.get("USD").get("rate")
rateGBP = valBTC.get("GBP").get("rate")
rateEUR = valBTC.get("EUR").get("rate")
disclaimer = jsonResponse.get("disclaimer")
print("""
// Bitcoin price value
// Updated: {updated}
> USD: {rateUSD}
> GBP: {rateGBP}
> EUR: {rateEUR}
// Disclaimer: {disclaimer}
""".format(updated=updated,
rateUSD=rateUSD,
rateGBP=rateGBP,
rateEUR=rateEUR,
disclaimer=disclaimer))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment