web and wiki

finance.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. # Keeps count of my beers.
  3. # See LICENSE file for copyright and license details.
  4. from os.path import join
  5. from time import gmtime, strftime
  6. from urllib.request import urlopen
  7. addresses = [
  8. '1M7Dgp5tkRapU4SUCZupKPVKA9EcomEKJr',
  9. ]
  10. api = 'https://blockchain.info/q'
  11. total = 0
  12. print(' * generating financial report')
  13. for i in addresses:
  14. curr = urlopen(join(api, 'getreceivedbyaddress', i))
  15. total += (float(curr.read()) / 100000000.)
  16. usd = float(urlopen(join(api, '24hrprice')).read())
  17. icandrink = total * usd
  18. cnt, tot = 0, 0
  19. beers = []
  20. while icandrink > 0:
  21. icandrink -= 2.5
  22. beers.append('<img src="static/beer11.png" alt="a cold beer" width="24">')
  23. cnt += 1
  24. tot += 1
  25. if cnt == 20:
  26. beers.append('<br>')
  27. cnt = 0
  28. page = "<h2>heads' financial report</h2>\n"
  29. page += '<h4>%s</h4>\n' % strftime('%a, %d %b %Y %H:%M:%S %z', gmtime())
  30. page += '<a href="/finance.py"><h4>generated with a script</h4></a>\n'
  31. page += '\n'.join(beers) + '\n'
  32. page += '<p>beer count: %d</p>\n' % tot
  33. with open('finance.html', 'w') as f:
  34. f.write(page)