Commit 87bf3980 authored by Max Dale's avatar Max Dale
Browse files

Initial backup of finished project for viewing

parents
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
FROM python:latest
COPY . ./code
RUN pip install requests
EXPOSE 8080:8080
\ No newline at end of file
The quick brown fox jumps over the lazy dog
\ No newline at end of file
"""
Mackenzie Dale
mrd214
11231692
"""
import requests
import sys
import time
def main():
ip_address = '172.17.0.1'
filename = sys.argv[1]
url = 'http://'+ ip_address + ':5000/api/'
running = True
while running:
data = open('./' + filename, "r")
selection = input("Request (r), Update (u), Create (c), or Delete (d) file? Quit (q)")
start = time.time()
if(selection == "r"):
result = requests.get(url + filename).json()
print("Retrieved:")
print(result[filename])
if(selection == "u"):
data = {'data':data}
result = requests.put(url + filename, data).json()
print("Updated:")
print(result[filename])
if(selection == "c"):
data = {'data':data}
result = requests.post(url + filename, data).json()
print("Created:")
print(result[filename])
if(selection == "d"):
result = requests.delete(url + filename)
print("Deleted")
if(selection == "q"):
running = False
end = time.time()
print("Elapsed time: " + str(end - start) + 's')
if __name__ == "__main__":
main()
\ No newline at end of file
FROM python:latest
COPY . ./code
RUN pip install flask-restful
EXPOSE 5050:5000
"""
Mackenzie Dale
mrd214
11231692
"""
from flask import Flask
from flask import request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
reversedStrings = {}
#Class that accepts a file name and data, and stores the data reversed in a dictionary with the file name as the key
class ReversedStrings(Resource):
#Get resource by filename
def get(self, fileName):
return {fileName:reversedStrings[fileName]}
#Update resource under file name to have new data
def put(self, fileName):
reversed = ""
data = request.form['data']
for i in data:
reversed = i + reversed
reversedStrings[fileName] = reversed
return {fileName:reversedStrings[fileName]}
#Create a new resource containing key filename and item reversed data (Essentially the same as put)
def post(self, fileName):
reversed = ""
data = request.form['data']
for i in data:
reversed = i + reversed
reversedStrings[fileName] = reversed
return {fileName:reversedStrings[fileName]}
#Delete the resource
def delete(self, fileName):
reversedStrings.pop(fileName)
api.add_resource(ReversedStrings, '/api/<string:fileName>')
if __name__ == '__main__':
app.run(host="0.0.0.0",debug=True)
\ No newline at end of file
version: "3.9"
services:
client:
build: ./Client
container_name: python_client
ports:
- "8080:8080"
volumes:
- ./:/code
stdin_open: true
tty: true
flask:
build: ./WebService
container_name: flask_server
ports:
- "5000:5000"
volumes:
- ./:/code
stdin_open: true
tty: true
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment