-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
100 lines (82 loc) · 3.57 KB
/
client.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
#!/usr/bin/env python3
# Import methods from the 21 Bitcoin Library
from two1.commands.config import Config
from two1.lib.wallet import Wallet
from two1.lib.bitrequests import BitTransferRequests
import json
import sys
import random
# Configure your Bitcoin wallet.
username = Config().username
wallet = Wallet()
requests = BitTransferRequests(wallet, username)
# farewells to use when user wishes to end client flow
bitcoin_pizza_goodbyes = ["Well, we hope you have a nice day, even without that tasty Bitcoin pizza!",
"To the moon!!! ┗(°0°)┛",
"Bitcoin for pizza? Sounded like a crazy idea anyway!",
"Keep calm and HODL!",
]
# server address
server_url = "http://localhost:5000/"
def pizza():
print("You are only a few steps away from buying Domino's pizza, 100% funded by Bitcoin!\n")
print("We'll need you to:\n * Pick a nearby store\n * Select your meal from the Domino's menu\n * Enter your delivery information")
# acquire zip code and then get menu for domino"s near zip code
zip_code = input("\nWhat is the zip code where you want your pizza delivered to: ")
find_stores_url = server_url + "getMenuForStoreID?zipCode=" + str(zip_code)
r = requests.get(url=find_stores_url).json()
# check if user is ok with nearest store
print("\nAddress: " + r["address"])
print("Phone: " + r["phone"])
print("Delivery Times: " + r["delivery_times"] + "\n")
ok = input("The above Domino's store will prepare and deliver your meal. Type 'ok' if this store works for you: ")
if ok != "ok":
print("\n" + random.choice(bitcoin_pizza_goodbyes))
sys.exit(1)
print("\n\n")
print("######################################")
print("# Menu #")
print("######################################")
counter = 0
for menuItem in r["menu"]:
print("(" + str(counter) + ") " + str(list(menuItem.keys())[0]))
counter = counter + 1
print("######################################")
print("# Menu #")
print("######################################")
print("\n")
# get desired menu items from user
orderItems = input("\nPlease give a comma separated list of the indices of the items you'd like to order from the menu above: ")
orderItems = orderItems.split(",")
chosenItems = []
for index in orderItems:
chosenItems.append(r["menu"][int(index)])
# make sure user typed the items they wanted
print("\n")
for i in chosenItems:
print(i)
ok = input("Are the above choices correct? type 'ok' if you want to order these items: ")
if ok != "ok":
print("\n" + random.choice(bitcoin_pizza_goodbyes))
sys.exit(1)
# get info necessary to create order
print("\nPlease enter the following information necessary to create your order")
parameters = {}
customer = {}
customer["firstName"] = input("First Name: ")
customer["lastName"] = input("Last Name: ")
address = {}
address["street"] = input("Street Address: ")
address["city"] = input("City: ")
address["Region"] = input("State: ")
address["PostalCode"] = input("Zip Code: ")
customer["address"] = address
parameters["customer"] = customer
parameters["items"] = [list(x.values())[0] for x in chosenItems]
parameters["storeID"] = r["store_id"]
# validate the user"s order and return the price in USD
resp = requests.post(server_url + "validate", data=parameters)
print(resp.text)
# start
if __name__ == "__main__":
pizza()