-1

Picture

I need to get the HTTP result, specifically the part with the BTC, ETH and USD prices (Under converted last in the image) and then save it as a variable in python so that I can display the price in the application. IDE: Pycharm Professional OS: Windows 10 I can also put the GET request for the URL into the python script, I just don't know how to narrow down the HTTP result to just the numbers in between the : and the , then save it as a variable to be displayed to the user I need to be able to save this piece of a http return from a get request

 },
  "last": 46775.88,
  "volume": 410.2487549,
  "converted_last": {
    "btc": 0.99807622,
    "eth": 11.872556,
    "usd": 46893
  },

and narrow it down to just BTC ETH and USD and then save it as a variable to be displayed to the user.

E_net4
  • 27,810
  • 13
  • 101
  • 139
A60
  • 1
  • 1

1 Answers1

1

What you need to do is take the response and convert the json into a dictionary (or object). Then you can access these as properties. I'm not sure what library you are using to make the request, but with requests, it would look like:

import requests

# make the request
response = requests.get('https://api.coingecko.com/api/v3/coins/bitcoin')
# get the dictionary from the response
json = response.json()
# narrow down the information needed from the response
tickers = json['tickers']
print(tickers[0]['converted_last']['btc'])