I want to transform the following result of a query into an API saved with ElasticSearch in a text to be used later.
b'{"BTC":{"USD":2403.99},"ETH":{"USD":222.1},"DASH":{"USD":179.04}}'
b'{"BTC":{"USD":2402.89},"ETH":{"USD":222.1},"DASH":{"USD":179.04}}'
...
I want to get it in a variable:
json_text = """
[
{"BTC":{"USD":2403.99},"ETH":{"USD":222.1},"DASH":{"USD":179.04}},
{"BTC":{"USD":2402.89},"ETH":{"USD":222.1},"DASH":{"USD":179.04}}
]
"""
In fact it will be in the following dataframe for financial calculation:
a = json.loads(json_text)
values = [(each["BTC"].get("USD"), each["ETH"].get("USD"), each["DASH"].get("USD")) for each in a]
However, if they have a different approach, of course I am interested in listening to them
output production and safeguard attempt
Here was how I produced the output and I try to save it in a text file with good form.
In the file Main.py
, I call a class Util with ut = Util
In this class I try to transform the result into a text:
import threading
from Elastic import Elastic
import urllib.request
from ValueAnalyse import ValueAnalyse
class Util:
def __init__(self):
pass
def disp(self,el,call,prices,assets):
threading.Timer(1, self.disp,[el,call,prices,assets]).start()
value = urllib.request.urlopen(call).read()
prices.append(value)
print(len(prices))
print("prices : ")
print(type(prices))
a = " ".join(str(x) for x in prices)
print(a)
va = ValueAnalyse(a)
el.store(assets,value)