In [1]:
import requests
import time
import getpass
import os
import json
import arrow

In [2]:
nowtime = arrow.now()

In [3]:
nowtime.for_json()


Out[3]:
'2017-08-19T13:24:28.190837+12:00'

In [4]:
myusr = getpass.getuser()

In [6]:
confpat = '/home/{}/.config'.format(myusr)

fulpat = '{}/blockchain.json'.format(confpat)

if 'blockchain.json' in os.listdir(confpat):
    pass
else:
    bcdic = dict({'oldbtc' : '0', 'oldeth' : '0', 'updated' : '2017-08-19T13:26:29.240023+12:00'})
    bcjs = json.dumps(bcdic)
    print(bcjs)
    # Writing our configuration file to 'example.cfg'
    with open(fulpat, 'w') as configfile:
        configfile.write(bcjs)
    
with open(fulpat, 'r') as faljs:
    #print(faljs.read())
    convjs = json.loads(faljs.read())
    
print(convjs)
oldbtc = convjs['oldbtc']
oldeth = convjs['oldeth']

payload = {'fsyms' : 'ETH,BTC', 'tsyms' : 'AUD'}

reqetc = requests.get('https://min-api.cryptocompare.com/data/pricemulti', params= payload)
nowtime = arrow.now()
etjs = reqetc.json()

if float(etjs['BTC']['AUD']) == float(oldbtc):
    btcchange = 'no change'
elif float(etjs['BTC']['AUD']) > float(oldbtc):
    btcchange = 'increase'
elif float(etjs['BTC']['AUD']) < float(oldbtc):
    btcchange = 'decrease'
    
if float(etjs['ETH']['AUD']) == float(oldeth):
    ethchange = 'no change'
elif float(etjs['ETH']['AUD']) > float(oldeth):
    ethchange = 'increase'
elif float(etjs['ETH']['AUD']) < float(oldeth):
    ethchange = 'decrease'
    
diffbtc = abs(float(etjs['BTC']['AUD'])-float(oldbtc))
diffeth = abs(float(etjs['ETH']['AUD'])-float(oldeth))
print(str(float(diffbtc)) + ' ' + str(float(diffeth)))
oldtime = convjs['updated']
print('AUD. BTC: {}. Old price: {}. {}. ETH: {}. Old price: {}. {}'.format(etjs['BTC']['AUD'], oldbtc, btcchange, etjs['ETH']['AUD'], oldeth, ethchange))
print('old time: ' + oldtime + ' current time: ' + nowtime.for_json())
#print(bt hchange)


bcdic = dict({'oldbtc' : etjs['BTC']['AUD'], 'oldeth' : etjs['ETH']['AUD'], 'btcdiff' : diffbtc, 'ethdiff' : diffeth, 'updated' : nowtime.for_json()})
bcjs = json.dumps(bcdic)

with open(fulpat, 'w') as configfile:
    configfile.write(bcjs)


{'oldeth': 391, 'oldbtc': 5491.67, 'updated': '2017-08-19T13:24:37.526247+12:00'}
0.0 0.0
AUD. BTC: 5491.67. Old price: 5491.67. no change. ETH: 391. Old price: 391. no change
old time: 2017-08-19T13:24:37.526247+12:00 current time: 2017-08-19T13:26:29.240023+12:00

In [ ]: