Skip to content

Commit

Permalink
examples: add a script showcasing the internet module by converting…
Browse files Browse the repository at this point in the history
… USD to EUR using live rates
  • Loading branch information
Wertzui123 committed Aug 25, 2024
1 parent 00c82cf commit ce9cc6b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/usd_to_euro/main.aspl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import internet
import json
import math

var usd = math.round(double(input("Enter a value of $ you want to convert to €: ")), 2)
var data = map<string, any>(json.decode(internet.get("http://open.er-api.com/v6/latest/USD").text)) // TODO: Use https here when it works
var rates = map<string, float>(data["rates"])
var rate = rates["EUR"]
var euro = math.round(usd * rate, 2)
print(usd + "$ ≙ " + euro + "€")

0 comments on commit ce9cc6b

Please sign in to comment.