summaryrefslogtreecommitdiffstats
path: root/bitvend.py
blob: 737e8b09ac22dac793263d4f7d5e323139eb1160 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import logging
import threading
import flask
from flask_qrcode import QRcode

from bitvend.mdb import CashlessMDBDevice
from bitvend.utils import to_local_currency, from_local_currency, format_btc, \
    sat_to_btc
from bitvend.processor import PaymentProcessor

logging.basicConfig(level=logging.INFO)

#from prometheus_client import start_http_server, Counter
#start_http_server(8000)

#coin_counter = Counter('coins_inserted', 'Number of coins inserted into machine')
#purchase_counter = Counter('purchases', 'Number of purchases')

dev = CashlessMDBDevice()
proc = PaymentProcessor(dev)

app = flask.Flask(__name__)
QRcode(app)

app.config['INPUT_ADDRESS'] = '12fkW5EBb3uBy1zD8pan4TcbabP5Fjato7'
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['ITEMS'] = [
    {
    'name': 'Club Mate',
    'image': '/static/img/club-mate.png',
    'value': 500,
    },
    {
    'name': 'Arduino Pro Micro',
    'image': '/static/img/promicro.png',
    'value': 1600,
    },
]
'''
    {
    'name': 'Arduino Pro Mini',
    'image': '',
    'value': 750,
    },
'''
@app.route('/')
def index():
    return flask.render_template(
        'index.html', items=app.config['ITEMS'])

@app.route('/begin/<int:amount>')
def begin_session(amount):
    dev.begin_session(amount)
    return 'ok'

@app.route('/cancel')
def cancel_session():
    dev.cancel_session()
    return 'ok'

@app.context_processor
def ctx_utils():
    return {
        'from_local_currency': from_local_currency,
        'to_local_currency': to_local_currency,
        'format_btc': format_btc,
        'sat_to_btc': sat_to_btc,
    }

if __name__ == "__main__":
    threading.Thread(target=app.run, kwargs={
        'host': '0.0.0.0'
        }, daemon=True).start()
    proc.start()
    dev.run()