-
Notifications
You must be signed in to change notification settings - Fork 3
/
sxsw.py
119 lines (86 loc) · 3.3 KB
/
sxsw.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
Subtledata SXSW Demo Application
AUTHOR
George Sibble
Chief Software Architect
Subtledata, Inc.
Github: sibblegp
************TO USE************
Set the following variables to valid Subtledata IDs:
--API_KEY
--LOCATION_ID
--USER_ID
--DEVICE_ID
LICENSE (The MIT License)
Copyright (c) 2013 Subtledata, Inc. "[email protected]"
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from flask import Flask, render_template, request
import subtledata
#Initialize Flask
APP = Flask(__name__)
#Turn on debugging to make life easier
APP.debug = True
#Set our API key to our Subtledata Web API
API_KEY = '@@@@@@@'
#Set our location ID
LOCATION_ID = 12345
#We will need a valid user ID and device ID to submit orders
USER_ID = 12345
DEVICE_ID = 12345
#Initialize the Subtledata Library with our API Key
SD = subtledata.SubtleData(API_KEY)
#Fetch our location since we will need it for all calls
DEV_GARAGE = SD.Locations.get(LOCATION_ID, include_menu=True)
#Main Route to show the menu
@APP.route('/', methods=['GET'])
def show_homepage():
"""
Show homepage will present the menu to our user
:return: Template(Menu.jinja2)
"""
#Get the items we want to display
items = DEV_GARAGE.menu.get_category(category_name='Bottle Beer').items
#Display our menu and associated items
return render_template("menu.jinja2", items=items[0:4])
#POST route to accept and create the order
@APP.route('/order', methods=['POST'])
def take_order():
"""
Receive our order and process it
:return: Template(confirmation.jinja2)
"""
#Set our seat number from the form
seat_number = request.form['seat_number']
#Set our ordered item from the form
ordered_item = request.form['ordered_item']
#Open a new ticket using our user and device ID
#Set its ticket name to a custom value so that we know which seat to go to
new_ticket = DEV_GARAGE.tables[0].open_ticket(USER_ID,
DEVICE_ID,
custom_ticket_name='Seat ' + str(seat_number))
#Add (stage) one of our items to our order
new_ticket.add_item_to_order(ordered_item, 1)
#Submit our order for processing
new_ticket.submit_order()
#Return the confirmation
return render_template('confirmation.jinja2', item_id=ordered_item)
#Start Flask
if __name__ == '__main__':
APP.run('0.0.0.0')