web and wiki

finance.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. '1Ho3MCkBBFqaaDLAquz8knKHxPeFJVezzY',
  10. ]
  11. api = 'https://blockchain.info/q'
  12. total = 0
  13. print(' * generating financial report')
  14. for i in addresses:
  15. curr = urlopen(join(api, 'getreceivedbyaddress', i))
  16. total += (float(curr.read()) / 100000000.)
  17. usd = float(urlopen(join(api, '24hrprice')).read())
  18. icandrink = total * usd
  19. cnt, tot = 0, 0
  20. beers = []
  21. while icandrink > 0:
  22. icandrink -= 2.5
  23. beers.append('<img src="static/beer11.png" alt="a cold beer" width="24">')
  24. cnt += 1
  25. tot += 1
  26. if cnt == 42:
  27. beers.append('<br>')
  28. cnt = 0
  29. page = "<h2>heads' financial report</h2>\n"
  30. page += '<h4>%s</h4>\n' % strftime('%a, %d %b %Y %H:%M:%S %z', gmtime())
  31. page += '<a href="/finance.py"><h4>generated with a script</h4></a>\n'
  32. page += '\n'.join(beers) + '\n'
  33. page += '<p>beer count: %d</p>\n' % tot
  34. with open('finance.html', 'w') as f:
  35. f.write(page)