Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bitcoin Tracker example's Coindesk API URL #1106

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ with the `font` parameter. You can read more about the available fonts

To get closer to a truly useful Pixlet app, we'll be pulling in some
Bitcoin data. CoinDesk's [Bitcoin Price Index
API](https://www.coindesk.com/coindesk-api) is free to use and
requires no authentication. We'll use Starlib's [http
API](https://developers.coindesk.com/documentation/legacy/Price/SingleSymbolPriceEndpoint/)
is free to use and requires no authentication. We'll use Starlib's [http
module](https://github.com/qri-io/starlib/tree/master/http) to
retrieve the data.

Expand All @@ -68,14 +68,14 @@ anything but the simplest applet.
load("render.star", "render")
load("http.star", "http")

COINDESK_PRICE_URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
COINDESK_PRICE_URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"

def main():
rep = http.get(COINDESK_PRICE_URL)
if rep.status_code != 200:
fail("Coindesk request failed with status %d", rep.status_code)

rate = rep.json()["bpi"]["USD"]["rate_float"]
rate = rep.json()["USD"]

return render.Root(
child = render.Text("BTC: %d USD" % rate)
Expand Down Expand Up @@ -113,7 +113,7 @@ load("render.star", "render")
load("http.star", "http")
load("encoding/base64.star", "base64")

COINDESK_PRICE_URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
COINDESK_PRICE_URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"

# Load Bitcoin icon from base64 encoded data
BTC_ICON = base64.decode("""
Expand All @@ -128,7 +128,7 @@ def main():
if rep.status_code != 200:
fail("CoinDesk request failed with status %d", rep.status_code)

rate = rep.json()["bpi"]["USD"]["rate_float"]
rate = rep.json()["USD"]

return render.Root(
child = render.Row( # Row lays out its children horizontally
Expand Down Expand Up @@ -166,7 +166,7 @@ load("render.star", "render")
load("http.star", "http")
load("encoding/base64.star", "base64")

COINDESK_PRICE_URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
COINDESK_PRICE_URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"

BTC_ICON = base64.decode("""
iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAlklEQVQ4T2NkwAH+H2T/jy7FaP+
Expand All @@ -180,7 +180,7 @@ def main():
if rep.status_code != 200:
fail("Coindesk request failed with status %d", rep.status_code)

rate = rep.json()["bpi"]["USD"]["rate_float"]
rate = rep.json()["USD"]

return render.Root(
child = render.Box( # This Box exists to provide vertical centering
Expand Down Expand Up @@ -216,7 +216,7 @@ load("http.star", "http")
load("encoding/base64.star", "base64")
load("cache.star", "cache")

COINDESK_PRICE_URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
COINDESK_PRICE_URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"

BTC_ICON = base64.decode("""
iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAlklEQVQ4T2NkwAH+H2T/jy7FaP+
Expand All @@ -235,7 +235,7 @@ def main():
rep = http.get(COINDESK_PRICE_URL)
if rep.status_code != 200:
fail("Coindesk request failed with status %d", rep.status_code)
rate = rep.json()["bpi"]["USD"]["rate_float"]
rate = rep.json()["USD"]
cache.set("btc_rate", str(int(rate)), ttl_seconds=240)

return render.Root(
Expand Down
14 changes: 10 additions & 4 deletions examples/bitcoin/bitcoin.star
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
load("http.star", "http")
load("icon.png", icon = "file")
load("encoding/base64.star", "base64")
load("render.star", "render")

COINDESK_PRICE_URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
COINDESK_PRICE_URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD"

BTC_ICON = icon.readall()
# Load Bitcoin icon from base64 encoded data
BTC_ICON = base64.decode("""
iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAAlklEQVQ4T2NkwAH+H2T/jy7FaP+
TEZtyDEG4Zi0TTPXXzoDF0A1DMQRsADbN6MZdO4NiENwQbAbERh1lWLzMmgFGo5iFZBDYEFwuwG
sISCPUIKyGgDRjAyBXYXMNIz5XgDQga8TpLboYgux8DO/AwoUuLiEqTLBFMcmxQ7V0gssgklIsL
AYozjsoBoE45OZi5DRBSnkCAMLhlPBiQGHlAAAAAElFTkSuQmCC
""")

def main():
rep = http.get(COINDESK_PRICE_URL, ttl_seconds = 240)
if rep.status_code != 200:
fail("Coindesk request failed with status %d", rep.status_code)
rate = rep.json()["bpi"]["USD"]["rate_float"]
rate = rep.json()["USD"]

return render.Root(
child = render.Box(
Expand Down