I am writing a python script which calls the API of ethermine.org, then I am using telegraf to input the data into influxdb and it is being displayed on grafana. Influxdb and telegraf accepts json format and the first two API pulls which I did work, they display the data in the following format(I put x's in place of the actual values that get returned):
{"time": xxx, "lastSeen": xxx, "reportedHashrate": xxx, "currentHashrate": xxx, "validShares": x, "invalidShares": 0, "staleShares": 0, "averageHashrate": x, "activeWorkers": x, "unpaid": xx, "unconfirmed": null, "coinsPerMin": xxxx, "usdPerMin": xxxx, "btcPerMin": xxxx}
However, the 3rd pull which I am trying to do seems to be outputting an extra '}' character and also seems to be formatted slightly differently(instead of just a tag like currentHashrate and a value it has a tag say price: then {two more tags} so almost like a list of tags within the price category, which is where I think the extra '}' might be coming from.
{"topMiners": [], "minedBlocks": [{"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}, {"number": x, "miner": "x", "time": x}], "poolStats": {"hashRate": x, "miners": x, "workers": x, "blocksPerHour": x}, "price": {"usd": xxx, "btc": xxx}}
Please note I am new to python so in my attempt to fix it using google I was unsuccessful as I am probably going about it the wrong way. I will upload screenshots of the error I am getting in telegraf, then also a screenshot of the python error I got when I attempted to fix it. Also find my code of the python script below
python error which relates to these lines of code I think
print(statsPool.text)
poolS=json.loads(statsPool.text)
print(f'{poolS["price"]}')
import json
import requests
# Miner - Statistics Armand
keyArmand = 'xxxxxxxxxx'
urlArmand = 'https://api.ethermine.org/miner/' + keyArmand + '/currentStats'
# Miner - Statistics Altus
keyAltus = 'xxxxxxxxxxx'
urlAltus = 'https://api.ethermine.org/miner/' + keyAltus + '/currentStats'
# PoolStats
urlPoolStats = 'https://api.ethermine.org' + '/poolStats'
#call 1
statsArmand = requests.get(urlArmand)
#call 2
statsAltus = requests.get(urlAltus)
#call 3
statsPool = requests.get(urlPoolStats)
print(json.dumps(json.loads(statsArmand.text)['data']))
print(json.dumps(json.loads(statsAltus.text)['data']))
#problem line (prints an extra '}' at the end
print(json.dumps(json.loads(statsPool.text)['data']))
#next 3 lines is what I tried to do to fix it (either need to get rid of the extra '}' at the end or I just need the price tag displayed in the correct format
print(statsPool.text)
poolS=json.loads(statsPool.text)
print(f'{poolS["price"]}')
As a summary: The 3rd python json API call is returning a different format to the first two, I would like to either reformat the 3rd one in the same format as the first two or just extract the price in USD(price: "USD" part) in the format (similar to say {"time": xxx}), because that is the only part I want to use.