Skip to content

Commit

Permalink
Update the code and add server side functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashraf-wan committed Feb 26, 2023
1 parent 40f70e7 commit ed8730f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
8 changes: 1 addition & 7 deletions 4.0/client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import json, requests
from urllib import response
from random import choice
import requests
import time

server = input("Enter the server IP address: ")
Expand Down Expand Up @@ -28,7 +26,6 @@
elif choice == "2":
user_name = input("What is you name?\n")
user_order = input("What would you like to order?\n")
# deepcode ignore SSRF: <Not very important because it is for fun>
order = requests.get(server + '/api/v1/order?id=' + user_order)
print(order.content.decode('utf-8'))
print("....")
Expand All @@ -37,8 +34,5 @@
pay = requests.get(server + '/api/v1/paying?method=' + method_payment)
print(pay.content.decode('utf-8'))
requests.get(server + '/api/v1/name?name=' + user_name)
time.sleep(10)
delivery = requests.get(server + '/api/v1/delivery')
print(delivery.content.decode('utf-8'))
else:
print("invalid options")
32 changes: 17 additions & 15 deletions 4.0/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,67 @@
from flask_restful import Resource, Api
import time
import json
import main as excel

menus_item = [
{
"id": 1,
"name": "Classic Pizza",
"price": "$8.00",
"line": "2"
"line": 2
},
{
"id": 2,
"name": "Pepperoni Pizza",
"price": "$10.00",
"line": "4"
"line": 4
},
{
"id": 3,
"name": "Cheese Pizza",
"price": "$12.00",
"line": "6"
"line": 6
},
{
"id": 4,
"name": "Meat Lover's Pizza",
"price": "$16.00",
"line": "8"
"line": 8
},
{
"id": 5,
"name": "Veggie Pizza",
"price": "$14.00",
"line": "10"
"line": 10
},
{
"id": 6,
"name": "Hawaiian Pizza",
"price": "$13.00",
"line": "12"
"line": 12
},
{
"id": 7,
"name": "Margherita Pizza",
"price": "$11.00",
"line": "14"
"line": 14
},
{
"id": 8,
"name": "BBQ Chicken Pizza",
"price": "$15.00",
"line": "16"
"line": 16
},
{
"id": 9,
"name": "Supreme Pizza",
"price": "$17.00",
"line": "18"
"line": 18
},
{
"id": 10,
"name": "Mushroom Pizza",
"price": "$12.00",
"line": "20"
"line": 20
}
]

Expand Down Expand Up @@ -94,10 +93,13 @@ def api_id():
if menu['id'] == id:
item = menu
break
f = open('report.txt','w+')
change_num = f.readlines(item['line'])
changed_num = int(change_num) + 1
f.writelines(changed_num[item['line']])
with open('report.txt','r') as f:
number1 = int(item['line']) - 1
reading = f.readlines()
line = int(reading[number1]) + 1
reading[number1] = str(line) + "\n"
with open('report.txt','w') as f:
f.write("".join(str(item) for item in reading))
if item:
return str("Your order is " + item['name'] + " and the price is " + item['price'])
else:
Expand Down
14 changes: 14 additions & 0 deletions 4.0/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import time, requests
x = 4
user_order = str(x)
user_name = str("bob")
server = "http://127.0.0.1:5000"
method_payment = "cash"
print("Test 1: Ordering a pizza")
try:
order = requests.get(server + '/api/v1/order?id=' + user_order)
print(order.content.decode('utf-8'))
time.sleep(2)
print("\033[1;32;40m Test 1 Successful")
except:
print("failed")
10 changes: 1 addition & 9 deletions 4.0/test/tester.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time, requests
from numpy import random
x = random.randint(4)
x = 4
user_order = str(x)
user_name = str("bob")
server = "http://127.0.0.1:5000"
Expand All @@ -22,10 +21,3 @@
print("\033[1;31;40m Test 2 failed")
time.sleep(2)
requests.get(server + '/api/v1/name?name=' + user_name)
print("Test 3: Delivery of the order")
try:
delivery = requests.get(server + '/api/v1/delivery')
time.sleep(2)
print("\033[1;32;40m Test 3 Successful")
except:
print("\033[1;31;40m Test 3 failed")

0 comments on commit ed8730f

Please sign in to comment.