Skip to content

Instantly share code, notes, and snippets.

@RomainL972
Created January 18, 2021 03:44
Show Gist options
  • Save RomainL972/4659e7eccc0a7e67fff85113e3d74043 to your computer and use it in GitHub Desktop.
Save RomainL972/4659e7eccc0a7e67fff85113e3d74043 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
from dateutil.parser import parse
def main():
fromcur = input("From currency : ")
tocur = input("To currency : ")
amount = float(input("Amount : "))
date = input("Date : ")
if not date:
date = "latest"
res = requests.get("https://api.exchangeratesapi.io/" + date + "?base=" + fromcur + "&symbols=" + tocur)
data = res.json()
rate = data["rates"][tocur]
print("{} {} = {} {}".format(amount, fromcur, amount * rate, tocur))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment