Skip to content

Instantly share code, notes, and snippets.

@ohsevin
Created April 24, 2018 23:49
Show Gist options
  • Save ohsevin/eef5d374fafd71cad61130e002256eec to your computer and use it in GitHub Desktop.
Save ohsevin/eef5d374fafd71cad61130e002256eec to your computer and use it in GitHub Desktop.
# bitstamp-widget
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import decimal
D = decimal.Decimal
import bitstamp.client
statusfile = '/home/artik/.bitstamp-widget-status.txt'
try:
c = bitstamp.client.Public()
btcusd = D(c.ticker()['last'])
rates = c.conversion_rate_usd_eur()
usdeur = (D(rates['buy']) + D(rates['sell'])) / D(2)
btceur = (btcusd * D(1) / usdeur).quantize(D('1.00'))
status = '$%.2f (€%.2f)' % (btcusd, btceur)
print(status)
with open(statusfile, 'w') as sf:
sf.write(status)
except Exception, e:
with open('/home/artik/bitstamp-widget-log.txt', 'a+') as log:
log.write(str(repr(e)) + '\n')
oldstatus = 'undef'
with open(statusfile, 'r') as sf:
oldstatus = sf.read()
print(oldstatus)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment