Mar-31-2021, 11:57 PM
It can be easier if take data first into Pandas,then get out all kind of formats.
A example and for plain text can use
A example and for plain text can use
df.to_string
.import requests import pandas as pd # Api url = 'https://min-api.cryptocompare.com/data/histoday?fsym=BTC&tsym=ETH&limit=5&aggregate=1&e=CCCAGG' data = requests.get(url).json()['Data'] # To Pandas df = pd.DataFrame.from_dict(data) # To txt with open('out.txt', 'w') as f: f.write(df.to_string(index=False))
Output: time high low open volumefrom volumeto close conversionType conversionSymbol
1616716800 33.01 32.01 32.36 14147.54 459354.17 32.39 invert
1616803200 32.93 32.19 32.39 14604.07 475135.19 32.62 invert
1616889600 33.10 32.58 32.62 12160.02 399198.72 33.08 invert
1616976000 33.11 31.50 33.08 16051.11 517814.86 31.73 invert
1617062400 32.23 31.54 31.73 14830.86 474005.03 31.92 invert
1617148800 32.34 30.28 31.92 21814.13 688238.39 30.71 invert