btcethaud
In [100]:
import requests
import time
import getpass
import os
import json
import arrow
In [101]:
import sqlite3
In [102]:
blockconnect = sqlite3.connect('blockchain.db')
In [103]:
bcon = blockconnect.cursor()
In [104]:
try:
bcon.execute('''CREATE TABLE blockchain
(datetime, ethval, bcval)''')
bcon.execute('INSERT INTO blockchain VALUES ({}, {}. {})'.format())
except Exception:
pass
In [105]:
nowtime = arrow.now()
In [106]:
myusr = getpass.getuser()
In [107]:
#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)
In [108]:
#bcdic
In [109]:
bcon.execute('INSERT INTO blockchain VALUES ({}, {}, {})'.format(nowtime.timestamp, etjs['BTC']['AUD'], etjs['ETH']['AUD']))
In [ ]:
blockconnect.commit()
In [110]:
for row in bcon.execute('SELECT * FROM blockchain'):
print(row)
In [111]:
#bcon.commit()
In [112]:
blockconnect.close()
In [ ]:
In [ ]:
Comments
Comments powered by Disqus