/
app.py
94 lines (81 loc) · 2.08 KB
/
app.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
__author__ = 'Keech'
from flask import Flask,send_from_directory,request
from Models.Session import Session
import os
import json
from suds.client import Client
from settings import APP_ROOT, openYaml
import yaml
from urllib import error
app = Flask(__name__)
Session = Session()
currentItemCount = 0
with openYaml() as stream:
data = yaml.load(stream)['wsdlUrl']
aUrl = data["aUrl"]
_coffeesOnHold = 7;
while True:
try:
aClient = Client(aUrl)
break
except (TimeoutError, error.URLError) as e:
pass
print("Client has started successfully")
tUrl = data["tUrl"]
while True:
try:
tClient= Client(tUrl)
break
except (TimeoutError, error.URLError) as e:
pass
print("Client has started successfully")
@app.route('/')
def init():
c = {'status': False}
if aClient is not None:
c['status'] = True
return json.dumps(c)
@app.route('/login')
def login():
user = Session.login(aClient)
s = json.dumps(user.__dict__)
return s
@app.route('/getMerchants')
def getMerchants():
b = False
if currentItemCount > 0:
b = True
merchants = Session.getMerchants(aClient, b)
ms =[]
s = None
print(merchants[merchants.keys()[0]])
for m in merchants:
print(m.__class__)
s = json.dumps(m)
ms.append(s)
return json.dumps(ms)
@app.route('/addTransaction', methods=['POST'])
def addTransaction():
global _coffeesOnHold
data = json.loads(request.form['coffeeOnHold'])
c = {'status':data}
if data:
_coffeesOnHold += 1
return str(_coffeesOnHold)
@app.route('/redeemCoffeeOnHold', methods=["POST"])
def redeemCoffee():
global _coffeesOnHold
_coffeesOnHold -= 1;
return str(_coffeesOnHold)
@app.route('/coffeesOnHold')
def coffeesOnHold():
return str(_coffeesOnHold)
@app.route('/webapp/<path:path>')
def send_webapp(path):
return send_from_directory('webapp', path)
@app.route('/frontend/<path:path>')
def send_frontend(path):
return send_from_directory('frontend', path)
if __name__ == '__main__':
app.debug = True
app.run()