api.py 473 B

12345678910111213141516171819
  1. import json
  2. from urllib.request import urlopen
  3. with urlopen("https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json") as response:
  4. source = response.read()
  5. data = json.loads(source)
  6. # print(json.dumps(data, indent=2))
  7. usd_rates = dict()
  8. for item in data['list']['resources']:
  9. name = item['resource']['fields']['name']
  10. price = item['resource']['fields']['price']
  11. usd_rates[name] = price
  12. print(50 * float(usd_rates['USD/INR']))