Created
April 24, 2018 23:49
-
-
Save ohsevin/eef5d374fafd71cad61130e002256eec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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