-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfinance.py
More file actions
executable file
·46 lines (35 loc) · 1.12 KB
/
finance.py
File metadata and controls
executable file
·46 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# Keeps count of my beers.
# See LICENSE file for copyright and license details.
from os.path import join
from time import gmtime, strftime
from urllib.request import urlopen
addresses = [
'1M7Dgp5tkRapU4SUCZupKPVKA9EcomEKJr',
'1Ho3MCkBBFqaaDLAquz8knKHxPeFJVezzY',
]
api = 'https://blockchain.info/q'
total = 0
print(' * generating financial report')
for i in addresses:
curr = urlopen(join(api, 'getreceivedbyaddress', i))
total += (float(curr.read()) / 100000000.)
usd = float(urlopen(join(api, '24hrprice')).read())
icandrink = total * usd
cnt, tot = 0, 0
beers = []
while icandrink > 0:
icandrink -= 2.5
beers.append('<img src="static/beer11.png" alt="a cold beer" width="24">')
cnt += 1
tot += 1
if cnt == 42:
beers.append('<br>')
cnt = 0
page = "<h2>heads' financial report</h2>\n"
page += '<h4>%s</h4>\n' % strftime('%a, %d %b %Y %H:%M:%S %z', gmtime())
page += '<a href="/finance.py"><h4>generated with a script</h4></a>\n'
page += '\n'.join(beers) + '\n'
page += '<p>beer count: %d</p>\n' % tot
with open('finance.html', 'w') as f:
f.write(page)