-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
94 lines (83 loc) · 2.61 KB
/
test.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
import requests
import json
# --------------Helper that help to get menu items---------------------------
host = "http://35.164.41.209:8082"
#host = '"http://localhost:8082'
def getMenu(section):
endpoint = "/menu/"+section
r = requests.get(url = host+endpoint)
if r.status_code == 200:
output = []
s = json.loads(r.content)
for sublist in s:
item = {}
item['name'] = str(sublist[0])
item['price'] = str(sublist[1])
output.append(item)
return output
data = {
"customer": {
"phone_number": "",
"name": ""
},
"pizzas": [
{
"cheese": "no cheese",
"meat": "Bacon, Grilled Chicken, Pepperoni",
"crust size": "6",
"veggies": "no veggies",
"sauce": "Ranch",
"quantity": 1
}
],
"AMZN ID": "amzn1.ask.account.AGX2CNUOPLHI3SAKVMAVLFZFRIQ3SHICA22Y4CZ7X244IARSTEGGAJFUH6UZVGKTIMWXP5NZXYEXA4VEF62NSJFC4NMMD7ZW6U6YLDUFY7JE4R6RUUKSCQBCIC3NAZWKUFNFPNDQ3LEKWARZR2GLCMJ57QGPRMPSWGDHHNGZYLOBVVENXP7JJPQWEZHNAOSQB2NI2HQQNHZSA3I",
"order ID": ""
}
def postOrder(order):
for pizza in order['pizzas']:
for key in ('cheese','meat','crust size','veggies','sauce'):
if 'no' in pizza[key]:
pizza[key] = ''
print order
endpoint = "/order"
r = requests.post(url = host+endpoint, json = order)
print r.status_code
print r.content
ids = [1]
def getOrderStatus(orderIds):
status = []
for orderId in orderIds:
endpoint = '/order/%s/status'%(orderId)
r = requests.get(url = host+endpoint)
print 'check order 1'
print '#################raw input##############'
print r
print r.content
if r.status_code == 200:
print '#############status 200################'
print r.content
st = {}
st['orderId'] = orderId
st['status'] = str(json.loads(r.content)['status'])
status.append(st)
return status
def autoOrderStatus(AMZNId):
endpoint = '/orders/%s'%(AMZNId)
r = requests.get(url = host+endpoint)
result = []
print 'check AMZN ID'
print '==============raw input================='
print r
print r.content
if r.status_code == 200:
print '==============status 200================='
print r.content
for orderStatus in json.loads(r.content)['orders']:
if orderStatus[2] != 'delivered':
result.append([str(orderStatus[x]) for x in [0,2]])
return result
print ("\n\n###########ORDER ID##############")
print getOrderStatus(ids)
print ('\n\n')
print ("============AMZN ID==============")
print autoOrderStatus(data["AMZN ID"])