L
L
Lavrenty Fedotov2017-03-04 18:11:03
Python
Lavrenty Fedotov, 2017-03-04 18:11:03

Write changed data from json to txt file?

r = requests.get('https://poloniex.com/public?command=returnTicker') #биток
r.json()
data = r.json()
x1 = data['USDT_BTC']['last']
r2 = requests.get('http://whattomine.com/coins.json?utf8=%E2%9C%93&commit=Calculate&eth=true&factor%5Beth_hr%5D='+str(user.name))
r2.json()
d2 = r2.json(object_pairs_hook=OrderedDict)
f = open("result.txt",'w')
for i in d2['coins']:
   btc = d2['coins'][i]['btc_revenue24']
   pr = float(x1)*float(btc)
f.writelines(i + '\n' + d2['coins'][i]['tag'][:4] + ': '+ d2['coins'][i]['estimated_rewards24'] + ' BTC: ' + d2['coins'][i]['btc_revenue24'] + ' Profit: ' + "%.2f" % float(pr) + '$' + '\n' for i in d2['coins'])
f.close()

The code quietly parses the data and displays the correct tag and estimated_rewards24, but:
I need to multiply btc_revenue24 and the data from x1 (pr = float(x1)*float(btc) )
as a result, it adds the last value to the txt file, and not for each i from d2['coins'] ( ' Profit: ' + "%.2f" % float(pr) )
The question is: how to make it multiply and enter data for each i, not just the last one

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Gorovoy, 2017-03-04
@Cnfc19932

I didn’t quite understand, why would he execute writelines () more than once? The call is not in a loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question