From 3ddd53750ef3dacb1c27bedb88b993b2a6e0d36d Mon Sep 17 00:00:00 2001 From: tsapen Date: Sun, 27 Oct 2019 21:05:40 +0300 Subject: [PATCH 1/5] Update hw6 web --- homeworks/homework_06_web/data.json | 9 + homeworks/homework_06_web/data_processing.py | 79 ++++++ .../homework_06_web/flight_service.logging | 23 ++ homeworks/homework_06_web/manage.py | 71 ++++++ homeworks/homework_06_web/request_dumps.txt | 238 ++++++++++++++++++ homeworks/homework_06_web/script.py | 85 +++++++ homeworks/homework_06_web/start_server.py | 3 + 7 files changed, 508 insertions(+) create mode 100644 homeworks/homework_06_web/data.json create mode 100644 homeworks/homework_06_web/data_processing.py create mode 100644 homeworks/homework_06_web/flight_service.logging create mode 100644 homeworks/homework_06_web/manage.py create mode 100644 homeworks/homework_06_web/request_dumps.txt create mode 100644 homeworks/homework_06_web/script.py create mode 100644 homeworks/homework_06_web/start_server.py diff --git a/homeworks/homework_06_web/data.json b/homeworks/homework_06_web/data.json new file mode 100644 index 00000000..099bc146 --- /dev/null +++ b/homeworks/homework_06_web/data.json @@ -0,0 +1,9 @@ +{ + "2": { + "departure_time": "16:00", + "arrival_time": "17:00", + "travel_time": "01:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" + } +} \ No newline at end of file diff --git a/homeworks/homework_06_web/data_processing.py b/homeworks/homework_06_web/data_processing.py new file mode 100644 index 00000000..5192f910 --- /dev/null +++ b/homeworks/homework_06_web/data_processing.py @@ -0,0 +1,79 @@ +import json +import sys +from os import path +from marshmallow import Schema, fields, ValidationError + +class Cnt: + def __init__(self): + self.cnt = 0 + if path.isfile("data.json"): + with open("data.json", 'r', encoding='utf-8')as file: + data = json.loads(file.read()) + if len(data) > 0: + self.cnt = max(data.keys()) + + def new_id(self): + self.cnt += 1 + return str(self.cnt) + +c = Cnt() + +class Flight(Schema): + departure_time = fields.Time(required=True) + arrival_time = fields.Time(required=True) + travel_time = fields.Time(required=True) + destination_airport = fields.Str(required=True) + type_aircraft = fields.Str(required=True) + +def is_valid(entry): + schema = Flight() + try: + schema.load(entry) + return True + except ValidationError: + return False + +def select_all(): + with open("data.json", 'r', encoding='utf-8')as file: + return file.read() + +def select(id_flight): + with open("data.json", 'r', encoding='utf-8')as file: + data = json.loads(file.read()) + if id_flight in data: + return True, json.dumps(data[id_flight]) + return False, "" + +def insert(entry): + with open("data.json", 'r', encoding='utf-8')as file: + data = json.loads(file.read()) + if is_valid(entry): + id_flight = c.new_id() + data[id_flight] = entry + with open("data.json", 'w', encoding='utf-8')as file: + json.dump(data, file, ensure_ascii=False, indent=4) + return id_flight + return None + +def update(id_flight, flight): + with open("data.json", 'r', encoding='utf-8')as file: + data = json.loads(file.read()) + id_flight = str(id_flight) + if is_valid(flight) and id_flight in data: + data[id_flight] = flight + with open("data.json", 'w', encoding='utf-8')as file: + json.dump(data, file, ensure_ascii=False, indent=4) + return True, "" + return False, '''id_flight not exist or flight format not valid''' + +def delete(id_flight): + with open("data.json", 'r', encoding='utf-8')as file: + data = json.loads(file.read()) + result = id_flight in data + message = "id_flight not exist" + if result: + message = "" + del data[id_flight] + with open("data.json", 'w', encoding='utf-8')as file: + json.dump(data, file, ensure_ascii=False, indent=4) + return result, message \ No newline at end of file diff --git a/homeworks/homework_06_web/flight_service.logging b/homeworks/homework_06_web/flight_service.logging new file mode 100644 index 00000000..27d37a60 --- /dev/null +++ b/homeworks/homework_06_web/flight_service.logging @@ -0,0 +1,23 @@ +INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) +INFO:root:show_flights, output all flights +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flights HTTP/1.1" 200 - +INFO:root:new_flight: new id_flight = 1 +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "POST /new_flight HTTP/1.1" 200 - +INFO:root:new_flight: new id_flight = 2 +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "POST /new_flight HTTP/1.1" 200 - +INFO:root:new_flight: new id_flight = None +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "POST /new_flight HTTP/1.1" 400 - +INFO:root:show_flights, output all flights +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flights HTTP/1.1" 200 - +INFO:root:show_flight, id_flight = 1: exists = False +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flight/1 HTTP/1.1" 400 - +INFO:root:show_flight, id_flight = 33: exists = False +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flight/33 HTTP/1.1" 400 - +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "PUT /update_flight HTTP/1.1" 200 - +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "PUT /update_flight HTTP/1.1" 400 - +INFO:root:delete_flight, id_flight = 1: result = True +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "DELETE /delete_flight HTTP/1.1" 200 - +INFO:root:delete_flight, id_flight = 4: result = False +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "DELETE /delete_flight HTTP/1.1" 400 - +INFO:root:show_flights, output all flights +INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flights HTTP/1.1" 200 - diff --git a/homeworks/homework_06_web/manage.py b/homeworks/homework_06_web/manage.py new file mode 100644 index 00000000..2f51f42b --- /dev/null +++ b/homeworks/homework_06_web/manage.py @@ -0,0 +1,71 @@ +from flask import Flask, jsonify, request +import data_processing as dp +from os import path +import json +import logging + +logging.basicConfig(filename="flight_service.logging", level=logging.INFO) + +app = Flask(__name__) + +@app.route("/show_flights", methods=["GET"]) +def show_flights(): + logging.info("show_flights, output all flights") + return dp.select_all() + +@app.route("/show_flight/", methods=["GET"]) +def show_flight(id_flight): + exist, flight = dp.select(id_flight) + logging.info("show_flight, id_flight = {}: exists = {}".format(id_flight, exist)) + if exist: + return flight + resp = jsonify(success=False) + resp.status_code = 400 + return resp + +@app.route("/new_flight", methods=["POST"]) +def new_flights(): + res = dp.insert(request.json) + logging.info("new_flight: new id_flight = {}".format(res)) + resp = jsonify(success=res if res else False) + resp.status_code = 200 if res else 400 + if res: + resp.message = "id_flight = {}".format(res) + return resp + +@app.route("/update_flight", methods=["PUT"]) +def update_flight(): + body = request.json + if "id_flight" not in body or "flight" not in body: + return False, '''"id_flight" of "flight not scecified in request''' + result, message = dp.update(body["id_flight"], body["flight"]) + if result: + resp = jsonify(success=True) + resp.status_code = 200 + else : + resp = jsonify(success=False) + resp.message = message + resp.status_code = 400 + return resp + +@app.route("/delete_flight", methods=["DELETE"]) +def delete_flights(): + body = request.json + if "id_flight" not in body: + return False, '''"id_flight" not scecified in request''' + res, message = dp.delete(body["id_flight"]) + logging.info("delete_flight, id_flight = {}: result = {}".format(body["id_flight"], res)) + if res: + resp = jsonify(success=True) + resp.status_code = 200 + else : + resp = jsonify(success=False) + resp.message = message + resp.status_code = 400 + return resp + +def start_server(): + if not path.isfile("data.json"): + with open("data.json","w", encoding='utf-8') as file: + json.dump(dict(), file, ensure_ascii=False, indent=4) + app.run() diff --git a/homeworks/homework_06_web/request_dumps.txt b/homeworks/homework_06_web/request_dumps.txt new file mode 100644 index 00000000..4feb3389 --- /dev/null +++ b/homeworks/homework_06_web/request_dumps.txt @@ -0,0 +1,238 @@ +0 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +< GET /show_flights HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< + +> HTTP/1.0 200 OK +> Content-Type: text/html; charset=utf-8 +> Content-Length: 2 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{} +1 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 200 True +< POST /new_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 133 +< Content-Type: application/json +< +< {"departure_time": "10:00", "arrival_time": "13:00", "travel_time": "03:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"} +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 16 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":"1"} + +2 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}) 200 True +< POST /new_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 138 +< Content-Type: application/json +< +< {"departure_time": "11:00", "arrival_time": "12:00", "travel_time": "01:00", "destination_airport": "Sheremetievo", "type_aircraft": "TU"} +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 16 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":"2"} + +3 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 400 False +< POST /new_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 133 +< Content-Type: application/json +< +< {"departure_time": "12:00", "arrival_time": "25:00", "travel_time": "02:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"} +> HTTP/1.0 400 BAD REQUEST +> Content-Type: application/json +> Content-Length: 18 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":false} + +4 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +< GET /show_flights HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< + +> HTTP/1.0 200 OK +> Content-Type: text/html; charset=utf-8 +> Content-Length: 387 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{ + "1": { + "departure_time": "10:00", + "arrival_time": "13:00", + "travel_time": "03:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" + }, + "2": { + "departure_time": "11:00", + "arrival_time": "12:00", + "travel_time": "01:00", + "destination_airport": "Sheremetievo", + "type_aircraft": "TU" + } +} +5 Urls(method='get', url='http://localhost:5000/show_flight/1', headers=None, json=None) 400 False +< GET /show_flight/1 HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< + +> HTTP/1.0 400 BAD REQUEST +> Content-Type: application/json +> Content-Length: 18 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":false} + +6 Urls(method='get', url='http://localhost:5000/show_flight/33', headers=None, json=None) 400 False +< GET /show_flight/33 HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< + +> HTTP/1.0 400 BAD REQUEST +> Content-Type: application/json +> Content-Length: 18 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":false} + +7 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '2', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 200 True +< PUT /update_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 163 +< Content-Type: application/json +< +< {"id_flight": "2", "flight": {"departure_time": "16:00", "arrival_time": "17:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"}} +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 17 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":true} + +8 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 400 False +< PUT /update_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 160 +< Content-Type: application/json +< +< {"id_flight": "3", "flight": {"departure_time": 1600, "arrival_time": "17:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"}} +> HTTP/1.0 400 BAD REQUEST +> Content-Type: application/json +> Content-Length: 18 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":false} + +9 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '1'}) 200 True +< DELETE /delete_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 18 +< Content-Type: application/json +< +< {"id_flight": "1"} +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 17 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":true} + +10 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '4'}) 400 False +< DELETE /delete_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 18 +< Content-Type: application/json +< +< {"id_flight": "4"} +> HTTP/1.0 400 BAD REQUEST +> Content-Type: application/json +> Content-Length: 18 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{"success":false} + +11 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +< GET /show_flights HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< + +> HTTP/1.0 200 OK +> Content-Type: text/html; charset=utf-8 +> Content-Length: 192 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sun, 27 Oct 2019 18:05:03 GMT +> +{ + "2": { + "departure_time": "16:00", + "arrival_time": "17:00", + "travel_time": "01:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" + } +} diff --git a/homeworks/homework_06_web/script.py b/homeworks/homework_06_web/script.py new file mode 100644 index 00000000..0a92fa4e --- /dev/null +++ b/homeworks/homework_06_web/script.py @@ -0,0 +1,85 @@ +from collections import namedtuple +import requests +from requests_toolbelt.utils.dump import dump_all + +Urls = namedtuple('Urls', ['method', 'url', 'headers', 'json']) + +jsons = { + "first insert": + { + "departure_time":"10:00", + "arrival_time":"13:00", + "travel_time":"03:00", + "destination_airport":"Vnukovo", + "type_aircraft":"TU" + }, + "second insert": + { + "departure_time":"11:00", + "arrival_time":"12:00", + "travel_time":"01:00", + "destination_airport":"Sheremetievo", + "type_aircraft":"TU" + }, + "bad insert": + { + "departure_time":"12:00", + "arrival_time":"25:00", + "travel_time":"02:00", + "destination_airport":"Vnukovo", + "type_aircraft":"TU" + }, + "update": + { + "id_flight": "2", + "flight": + { + "departure_time":"16:00", + "arrival_time":"17:00", + "travel_time":"01:00", + "destination_airport":"Vnukovo", + "type_aircraft":"TU" + } + }, + "bad update": + { + "id_flight": "3", + "flight": + { + "departure_time":1600, + "arrival_time":"17:00", + "travel_time":"01:00", + "destination_airport":"Vnukovo", + "type_aircraft":"TU" + } + }, + "delete": + { + "id_flight": "1", + }, + "bad delete": + { + "id_flight": "4", + } +} + +with open('request_dumps.txt', 'w') as f: + for index, url in enumerate([ + Urls('get', 'http://localhost:5000/show_flights', None, None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["first insert"]), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["second insert"]), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["bad insert"]), + Urls('get', 'http://localhost:5000/show_flights', None, None), + Urls('get', 'http://localhost:5000/show_flight/1', None, None), + Urls('get', 'http://localhost:5000/show_flight/33', None, None), + Urls('put', 'http://localhost:5000/update_flight', None, jsons["update"]), + Urls('put', 'http://localhost:5000/update_flight', None, jsons["bad update"]), + Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["delete"]), + Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["bad delete"]), + Urls('get', 'http://localhost:5000/show_flights', None, None), + ]): + resp = requests.request(method=url.method, url=url.url, headers=url.headers, json=url.json) + print(index, url, resp.status_code, resp.ok, file=f) + print(dump_all(resp).decode('utf-8'), file=f) + + diff --git a/homeworks/homework_06_web/start_server.py b/homeworks/homework_06_web/start_server.py new file mode 100644 index 00000000..ea2c7af3 --- /dev/null +++ b/homeworks/homework_06_web/start_server.py @@ -0,0 +1,3 @@ +from manage import start_server + +start_server() \ No newline at end of file From 85ce81a2a2105f291b7ec78e862026e1c2949f4d Mon Sep 17 00:00:00 2001 From: tsapen Date: Sun, 27 Oct 2019 21:06:30 +0300 Subject: [PATCH 2/5] Update hw6 web --- homeworks/homework_06_web/data_processing.py | 19 +++-- homeworks/homework_06_web/manage.py | 22 +++-- homeworks/homework_06_web/script.py | 88 ++++++++++---------- 3 files changed, 75 insertions(+), 54 deletions(-) diff --git a/homeworks/homework_06_web/data_processing.py b/homeworks/homework_06_web/data_processing.py index 5192f910..aafee5dd 100644 --- a/homeworks/homework_06_web/data_processing.py +++ b/homeworks/homework_06_web/data_processing.py @@ -3,6 +3,7 @@ from os import path from marshmallow import Schema, fields, ValidationError + class Cnt: def __init__(self): self.cnt = 0 @@ -16,8 +17,10 @@ def new_id(self): self.cnt += 1 return str(self.cnt) + c = Cnt() + class Flight(Schema): departure_time = fields.Time(required=True) arrival_time = fields.Time(required=True) @@ -25,18 +28,21 @@ class Flight(Schema): destination_airport = fields.Str(required=True) type_aircraft = fields.Str(required=True) + def is_valid(entry): schema = Flight() try: - schema.load(entry) - return True + schema.load(entry) + return True except ValidationError: return False + def select_all(): with open("data.json", 'r', encoding='utf-8')as file: return file.read() + def select(id_flight): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) @@ -44,6 +50,7 @@ def select(id_flight): return True, json.dumps(data[id_flight]) return False, "" + def insert(entry): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) @@ -55,6 +62,7 @@ def insert(entry): return id_flight return None + def update(id_flight, flight): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) @@ -62,11 +70,12 @@ def update(id_flight, flight): if is_valid(flight) and id_flight in data: data[id_flight] = flight with open("data.json", 'w', encoding='utf-8')as file: - json.dump(data, file, ensure_ascii=False, indent=4) + json.dump(data, file, ensure_ascii=False, indent=4) return True, "" return False, '''id_flight not exist or flight format not valid''' -def delete(id_flight): + +def delete(id_flight): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) result = id_flight in data @@ -76,4 +85,4 @@ def delete(id_flight): del data[id_flight] with open("data.json", 'w', encoding='utf-8')as file: json.dump(data, file, ensure_ascii=False, indent=4) - return result, message \ No newline at end of file + return result, message diff --git a/homeworks/homework_06_web/manage.py b/homeworks/homework_06_web/manage.py index 2f51f42b..a9c654a1 100644 --- a/homeworks/homework_06_web/manage.py +++ b/homeworks/homework_06_web/manage.py @@ -8,20 +8,25 @@ app = Flask(__name__) + @app.route("/show_flights", methods=["GET"]) def show_flights(): logging.info("show_flights, output all flights") return dp.select_all() + @app.route("/show_flight/", methods=["GET"]) def show_flight(id_flight): exist, flight = dp.select(id_flight) - logging.info("show_flight, id_flight = {}: exists = {}".format(id_flight, exist)) + logging.info( + "show_flight, id_flight = {}: exists = {}".format( + id_flight, exist)) if exist: return flight resp = jsonify(success=False) resp.status_code = 400 - return resp + return resp + @app.route("/new_flight", methods=["POST"]) def new_flights(): @@ -33,6 +38,7 @@ def new_flights(): resp.message = "id_flight = {}".format(res) return resp + @app.route("/update_flight", methods=["PUT"]) def update_flight(): body = request.json @@ -42,30 +48,34 @@ def update_flight(): if result: resp = jsonify(success=True) resp.status_code = 200 - else : + else: resp = jsonify(success=False) resp.message = message resp.status_code = 400 return resp + @app.route("/delete_flight", methods=["DELETE"]) def delete_flights(): body = request.json if "id_flight" not in body: return False, '''"id_flight" not scecified in request''' res, message = dp.delete(body["id_flight"]) - logging.info("delete_flight, id_flight = {}: result = {}".format(body["id_flight"], res)) + logging.info( + "delete_flight, id_flight = {}: result = {}".format( + body["id_flight"], res)) if res: resp = jsonify(success=True) resp.status_code = 200 - else : + else: resp = jsonify(success=False) resp.message = message resp.status_code = 400 return resp + def start_server(): if not path.isfile("data.json"): - with open("data.json","w", encoding='utf-8') as file: + with open("data.json", "w", encoding='utf-8') as file: json.dump(dict(), file, ensure_ascii=False, indent=4) app.run() diff --git a/homeworks/homework_06_web/script.py b/homeworks/homework_06_web/script.py index 0a92fa4e..0b6716f8 100644 --- a/homeworks/homework_06_web/script.py +++ b/homeworks/homework_06_web/script.py @@ -5,59 +5,59 @@ Urls = namedtuple('Urls', ['method', 'url', 'headers', 'json']) jsons = { - "first insert": + "first insert": { - "departure_time":"10:00", - "arrival_time":"13:00", - "travel_time":"03:00", - "destination_airport":"Vnukovo", - "type_aircraft":"TU" + "departure_time": "10:00", + "arrival_time": "13:00", + "travel_time": "03:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" }, - "second insert": + "second insert": { - "departure_time":"11:00", - "arrival_time":"12:00", - "travel_time":"01:00", - "destination_airport":"Sheremetievo", - "type_aircraft":"TU" + "departure_time": "11:00", + "arrival_time": "12:00", + "travel_time": "01:00", + "destination_airport": "Sheremetievo", + "type_aircraft": "TU" }, - "bad insert": + "bad insert": { - "departure_time":"12:00", - "arrival_time":"25:00", - "travel_time":"02:00", - "destination_airport":"Vnukovo", - "type_aircraft":"TU" + "departure_time": "12:00", + "arrival_time": "25:00", + "travel_time": "02:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" }, - "update": + "update": { "id_flight": "2", "flight": { - "departure_time":"16:00", - "arrival_time":"17:00", - "travel_time":"01:00", - "destination_airport":"Vnukovo", - "type_aircraft":"TU" + "departure_time": "16:00", + "arrival_time": "17:00", + "travel_time": "01:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" } }, - "bad update": + "bad update": { "id_flight": "3", "flight": { - "departure_time":1600, - "arrival_time":"17:00", - "travel_time":"01:00", - "destination_airport":"Vnukovo", - "type_aircraft":"TU" + "departure_time": 1600, + "arrival_time": "17:00", + "travel_time": "01:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" } }, - "delete": + "delete": { "id_flight": "1", }, - "bad delete": + "bad delete": { "id_flight": "4", } @@ -65,21 +65,23 @@ with open('request_dumps.txt', 'w') as f: for index, url in enumerate([ - Urls('get', 'http://localhost:5000/show_flights', None, None), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["first insert"]), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["second insert"]), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["bad insert"]), - Urls('get', 'http://localhost:5000/show_flights', None, None), + Urls('get', 'http://localhost:5000/show_flights', None, None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["first insert"]), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["second insert"]), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["bad insert"]), + Urls('get', 'http://localhost:5000/show_flights', None, None), Urls('get', 'http://localhost:5000/show_flight/1', None, None), Urls('get', 'http://localhost:5000/show_flight/33', None, None), - Urls('put', 'http://localhost:5000/update_flight', None, jsons["update"]), + Urls('put', 'http://localhost:5000/update_flight', None, jsons["update"]), Urls('put', 'http://localhost:5000/update_flight', None, jsons["bad update"]), - Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["delete"]), - Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["bad delete"]), + Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["delete"]), + Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["bad delete"]), Urls('get', 'http://localhost:5000/show_flights', None, None), ]): - resp = requests.request(method=url.method, url=url.url, headers=url.headers, json=url.json) + resp = requests.request( + method=url.method, + url=url.url, + headers=url.headers, + json=url.json) print(index, url, resp.status_code, resp.ok, file=f) print(dump_all(resp).decode('utf-8'), file=f) - - From 306e77b40b50ac404d07c87402b6e7f8fc0555ee Mon Sep 17 00:00:00 2001 From: tsapen Date: Sun, 27 Oct 2019 21:12:04 +0300 Subject: [PATCH 3/5] Update hw6 web --- homeworks/homework_06_web/start_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeworks/homework_06_web/start_server.py b/homeworks/homework_06_web/start_server.py index ea2c7af3..33c7bedb 100644 --- a/homeworks/homework_06_web/start_server.py +++ b/homeworks/homework_06_web/start_server.py @@ -1,3 +1,3 @@ from manage import start_server -start_server() \ No newline at end of file +start_server() From dd64d9a19f4ecb8c5db32e047d19174aff1cbdf5 Mon Sep 17 00:00:00 2001 From: tsapen Date: Sat, 2 Nov 2019 19:05:55 +0300 Subject: [PATCH 4/5] Update hw6 web --- homeworks/homework_06_web/data.json | 18 +- homeworks/homework_06_web/data_processing.py | 62 ++++-- .../homework_06_web/flight_service.logging | 54 +++-- homeworks/homework_06_web/manage.py | 73 ++++--- homeworks/homework_06_web/request_dumps.txt | 197 +++++++++++------- homeworks/homework_06_web/script.py | 23 +- 6 files changed, 273 insertions(+), 154 deletions(-) diff --git a/homeworks/homework_06_web/data.json b/homeworks/homework_06_web/data.json index 099bc146..f78ebe01 100644 --- a/homeworks/homework_06_web/data.json +++ b/homeworks/homework_06_web/data.json @@ -1,7 +1,21 @@ { "2": { - "departure_time": "16:00", - "arrival_time": "17:00", + "departure_time": "11:00", + "arrival_time": "12:00", + "travel_time": "01:00", + "destination_airport": "Sheremetievo", + "type_aircraft": "TU" + }, + "3": { + "departure_time": "06:00", + "arrival_time": "08:00", + "travel_time": "02:00", + "destination_airport": "Sheremetievo", + "type_aircraft": "TU" + }, + "4": { + "departure_time": "10:00", + "arrival_time": "11:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU" diff --git a/homeworks/homework_06_web/data_processing.py b/homeworks/homework_06_web/data_processing.py index aafee5dd..f7c76aac 100644 --- a/homeworks/homework_06_web/data_processing.py +++ b/homeworks/homework_06_web/data_processing.py @@ -38,51 +38,69 @@ def is_valid(entry): return False -def select_all(): +def select_all(sort_by, filter_field, filter_value): with open("data.json", 'r', encoding='utf-8')as file: - return file.read() + res = json.loads(file.read()) + if len(res) == 0: + res = [] + else: + res = [{"id_flight": i, "flight": res[i]} for i in res] + if filter_field is not None and filter_value is not None and len(res) > 0: + try: + res = [i for i in res if i["flight"][filter_field] == filter_value] + except BaseException: + return None + if sort_by is not None and len(res) > 0: + try: + res.sort(key=lambda a: a["flight"][sort_by]) + except BaseException: + return None + print(res) + return res def select(id_flight): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) - if id_flight in data: - return True, json.dumps(data[id_flight]) - return False, "" + try: + return True, data[str(id_flight)] + except BaseException: + return False, "" def insert(entry): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) if is_valid(entry): - id_flight = c.new_id() - data[id_flight] = entry + key = c.new_id() + data[key] = entry with open("data.json", 'w', encoding='utf-8')as file: json.dump(data, file, ensure_ascii=False, indent=4) - return id_flight + return key return None def update(id_flight, flight): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) - id_flight = str(id_flight) - if is_valid(flight) and id_flight in data: - data[id_flight] = flight - with open("data.json", 'w', encoding='utf-8')as file: - json.dump(data, file, ensure_ascii=False, indent=4) - return True, "" + if is_valid(flight): + try: + data[str(id_flight)] = flight + with open("data.json", 'w', encoding='utf-8')as file: + json.dump(data, file, ensure_ascii=False, indent=4) + return True, "" + except BaseException: + pass return False, '''id_flight not exist or flight format not valid''' def delete(id_flight): with open("data.json", 'r', encoding='utf-8')as file: data = json.loads(file.read()) - result = id_flight in data - message = "id_flight not exist" - if result: - message = "" - del data[id_flight] - with open("data.json", 'w', encoding='utf-8')as file: - json.dump(data, file, ensure_ascii=False, indent=4) - return result, message + try: + del data[str(id_flight)] + with open("data.json", 'w', encoding='utf-8')as file: + json.dump(data, file, ensure_ascii=False, indent=4) + return True, "" + except BaseException: + return False, "id_flight not exist" diff --git a/homeworks/homework_06_web/flight_service.logging b/homeworks/homework_06_web/flight_service.logging index 27d37a60..867f1fb3 100644 --- a/homeworks/homework_06_web/flight_service.logging +++ b/homeworks/homework_06_web/flight_service.logging @@ -1,23 +1,31 @@ -INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) -INFO:root:show_flights, output all flights -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flights HTTP/1.1" 200 - -INFO:root:new_flight: new id_flight = 1 -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "POST /new_flight HTTP/1.1" 200 - -INFO:root:new_flight: new id_flight = 2 -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "POST /new_flight HTTP/1.1" 200 - -INFO:root:new_flight: new id_flight = None -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "POST /new_flight HTTP/1.1" 400 - -INFO:root:show_flights, output all flights -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flights HTTP/1.1" 200 - -INFO:root:show_flight, id_flight = 1: exists = False -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flight/1 HTTP/1.1" 400 - -INFO:root:show_flight, id_flight = 33: exists = False -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flight/33 HTTP/1.1" 400 - -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "PUT /update_flight HTTP/1.1" 200 - -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "PUT /update_flight HTTP/1.1" 400 - -INFO:root:delete_flight, id_flight = 1: result = True -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "DELETE /delete_flight HTTP/1.1" 200 - -INFO:root:delete_flight, id_flight = 4: result = False -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "DELETE /delete_flight HTTP/1.1" 400 - -INFO:root:show_flights, output all flights -INFO:werkzeug:127.0.0.1 - - [27/Oct/2019 21:05:03] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:04:29,888 - werkzeug - INFO - * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) +2019-11-02 19:04:31,223 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0005, 'response': , 'http_status': 200} +2019-11-02 19:04:31,223 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:04:31,228 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0014, 'response': , 'http_status': 200} +2019-11-02 19:04:31,229 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:04:31,236 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0039, 'response': , 'http_status': 200} +2019-11-02 19:04:31,236 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:04:31,240 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0006, 'response': , 'http_status': 400} +2019-11-02 19:04:31,240 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 400 - +2019-11-02 19:04:31,244 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0004, 'response': , 'http_status': 200} +2019-11-02 19:04:31,244 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:04:31,247 - flask.app - INFO - {'url': 'http://localhost:5000/show_flight/1', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0002, 'response': , 'http_status': 200} +2019-11-02 19:04:31,247 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flight/1 HTTP/1.1" 200 - +2019-11-02 19:04:31,251 - flask.app - INFO - {'url': 'http://localhost:5000/show_flight/33', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0002, 'response': , 'http_status': 400} +2019-11-02 19:04:31,251 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flight/33 HTTP/1.1" 400 - +2019-11-02 19:04:31,256 - flask.app - INFO - {'url': 'http://localhost:5000/update_flight', 'args': {}, 'body': {'id_flight': '1', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, 'req_method': 'PUT', 'duration': 0.0019, 'response': , 'http_status': 200} +2019-11-02 19:04:31,257 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "PUT /update_flight HTTP/1.1" 200 - +2019-11-02 19:04:31,262 - flask.app - INFO - {'url': 'http://localhost:5000/update_flight', 'args': {}, 'body': {'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, 'req_method': 'PUT', 'duration': 0.0007, 'response': , 'http_status': 400} +2019-11-02 19:04:31,262 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "PUT /update_flight HTTP/1.1" 400 - +2019-11-02 19:04:31,266 - flask.app - INFO - {'url': 'http://localhost:5000/delete_flight', 'args': {}, 'body': {'id_flight': '1'}, 'req_method': 'DELETE', 'duration': 0.0005, 'response': , 'http_status': 200} +2019-11-02 19:04:31,266 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "DELETE /delete_flight HTTP/1.1" 200 - +2019-11-02 19:04:31,269 - flask.app - INFO - {'url': 'http://localhost:5000/delete_flight', 'args': {}, 'body': {'id_flight': '4'}, 'req_method': 'DELETE', 'duration': 0.0003, 'response': , 'http_status': 400} +2019-11-02 19:04:31,270 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "DELETE /delete_flight HTTP/1.1" 400 - +2019-11-02 19:04:31,275 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0007, 'response': , 'http_status': 200} +2019-11-02 19:04:31,276 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:04:31,283 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '06:00', 'arrival_time': '08:00', 'travel_time': '02:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0012, 'response': , 'http_status': 200} +2019-11-02 19:04:31,283 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:04:31,288 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '10:00', 'arrival_time': '11:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.001, 'response': , 'http_status': 200} +2019-11-02 19:04:31,288 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:04:31,293 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', 'args': {'sort_by': 'arrival_time', 'filter_field': 'destination_airport', 'filter_value': 'Sheremetievo'}, 'body': None, 'req_method': 'GET', 'duration': 0.0005, 'response': , 'http_status': 200} +2019-11-02 19:04:31,293 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo HTTP/1.1" 200 - diff --git a/homeworks/homework_06_web/manage.py b/homeworks/homework_06_web/manage.py index a9c654a1..ce65af27 100644 --- a/homeworks/homework_06_web/manage.py +++ b/homeworks/homework_06_web/manage.py @@ -1,41 +1,48 @@ -from flask import Flask, jsonify, request +from flask import Flask, jsonify, request, g import data_processing as dp from os import path import json import logging - -logging.basicConfig(filename="flight_service.logging", level=logging.INFO) +import time app = Flask(__name__) @app.route("/show_flights", methods=["GET"]) def show_flights(): - logging.info("show_flights, output all flights") - return dp.select_all() + sort_by = request.args.get("sort_by") + filter_field = request.args.get("filter_field", default=None) + filter_value = request.args.get("filter_value", default=None) + resp = jsonify( + success=True, + result=dp.select_all( + sort_by, + filter_field, + filter_value)) + return resp @app.route("/show_flight/", methods=["GET"]) def show_flight(id_flight): exist, flight = dp.select(id_flight) - logging.info( - "show_flight, id_flight = {}: exists = {}".format( - id_flight, exist)) if exist: - return flight - resp = jsonify(success=False) - resp.status_code = 400 + resp = jsonify(success=True, flight=flight) + resp.status_code = 200 + else: + resp = jsonify(success=False) + resp.status_code = 400 return resp @app.route("/new_flight", methods=["POST"]) -def new_flights(): +def new_flight(): res = dp.insert(request.json) - logging.info("new_flight: new id_flight = {}".format(res)) - resp = jsonify(success=res if res else False) - resp.status_code = 200 if res else 400 - if res: - resp.message = "id_flight = {}".format(res) + if res is not None: + resp = jsonify(success=True, id_flight=res) + resp.status_code = 200 + else: + resp = jsonify(success=False) + resp.status_code = 400 return resp @@ -49,8 +56,7 @@ def update_flight(): resp = jsonify(success=True) resp.status_code = 200 else: - resp = jsonify(success=False) - resp.message = message + resp = jsonify(success=False, message=message) resp.status_code = 400 return resp @@ -61,15 +67,11 @@ def delete_flights(): if "id_flight" not in body: return False, '''"id_flight" not scecified in request''' res, message = dp.delete(body["id_flight"]) - logging.info( - "delete_flight, id_flight = {}: result = {}".format( - body["id_flight"], res)) if res: resp = jsonify(success=True) resp.status_code = 200 else: - resp = jsonify(success=False) - resp.message = message + resp = jsonify(success=False, message=message) resp.status_code = 400 return resp @@ -78,4 +80,27 @@ def start_server(): if not path.isfile("data.json"): with open("data.json", "w", encoding='utf-8') as file: json.dump(dict(), file, ensure_ascii=False, indent=4) + + logging.basicConfig( + filename="flight_service.logging", + level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') + + @app.before_request + def timer_on(): + g.start_handlefunc = time.time() + + @app.after_request + def log_request(resp): + dur = round(time.time() - g.start_handlefunc, 4) + app.logger.info({ + "url": request.url, + "args": dict(request.args), + "body": request.json, + "req_method": request.method, + "duration": dur, + "response": resp, + "http_status": resp.status_code + }) + return resp app.run() diff --git a/homeworks/homework_06_web/request_dumps.txt b/homeworks/homework_06_web/request_dumps.txt index 4feb3389..c36da254 100644 --- a/homeworks/homework_06_web/request_dumps.txt +++ b/homeworks/homework_06_web/request_dumps.txt @@ -1,4 +1,4 @@ -0 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +0 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True < GET /show_flights HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -8,13 +8,14 @@ < > HTTP/1.0 200 OK -> Content-Type: text/html; charset=utf-8 -> Content-Length: 2 +> Content-Type: application/json +> Content-Length: 29 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{} -1 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 200 True +{"result":[],"success":true} + +1 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 200 True < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -27,13 +28,13 @@ < {"departure_time": "10:00", "arrival_time": "13:00", "travel_time": "03:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"} > HTTP/1.0 200 OK > Content-Type: application/json -> Content-Length: 16 +> Content-Length: 33 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":"1"} - -2 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}) 200 True +{"id_flight":"1","success":true} + +2 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}) 200 True < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -46,13 +47,13 @@ < {"departure_time": "11:00", "arrival_time": "12:00", "travel_time": "01:00", "destination_airport": "Sheremetievo", "type_aircraft": "TU"} > HTTP/1.0 200 OK > Content-Type: application/json -> Content-Length: 16 +> Content-Length: 33 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":"2"} - -3 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 400 False +{"id_flight":"2","success":true} + +3 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 400 False < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -67,11 +68,11 @@ > Content-Type: application/json > Content-Length: 18 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":false} - -4 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +{"success":false} + +4 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True < GET /show_flights HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -81,28 +82,14 @@ < > HTTP/1.0 200 OK -> Content-Type: text/html; charset=utf-8 -> Content-Length: 387 +> Content-Type: application/json +> Content-Length: 337 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{ - "1": { - "departure_time": "10:00", - "arrival_time": "13:00", - "travel_time": "03:00", - "destination_airport": "Vnukovo", - "type_aircraft": "TU" - }, - "2": { - "departure_time": "11:00", - "arrival_time": "12:00", - "travel_time": "01:00", - "destination_airport": "Sheremetievo", - "type_aircraft": "TU" - } -} -5 Urls(method='get', url='http://localhost:5000/show_flight/1', headers=None, json=None) 400 False +{"result":[{"flight":{"arrival_time":"13:00","departure_time":"10:00","destination_airport":"Vnukovo","travel_time":"03:00","type_aircraft":"TU"},"id_flight":"1"},{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} + +5 Urls(method='get', url='http://localhost:5000/show_flight/1', headers=None, json=None) 200 True < GET /show_flight/1 HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -111,15 +98,15 @@ < Connection: keep-alive < -> HTTP/1.0 400 BAD REQUEST +> HTTP/1.0 200 OK > Content-Type: application/json -> Content-Length: 18 +> Content-Length: 151 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":false} - -6 Urls(method='get', url='http://localhost:5000/show_flight/33', headers=None, json=None) 400 False +{"flight":{"arrival_time":"13:00","departure_time":"10:00","destination_airport":"Vnukovo","travel_time":"03:00","type_aircraft":"TU"},"success":true} + +6 Urls(method='get', url='http://localhost:5000/show_flight/33', headers=None, json=None) 400 False < GET /show_flight/33 HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -132,11 +119,11 @@ > Content-Type: application/json > Content-Length: 18 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":false} - -7 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '2', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 200 True +{"success":false} + +7 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '1', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 200 True < PUT /update_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -146,16 +133,16 @@ < Content-Length: 163 < Content-Type: application/json < -< {"id_flight": "2", "flight": {"departure_time": "16:00", "arrival_time": "17:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"}} +< {"id_flight": "1", "flight": {"departure_time": "16:00", "arrival_time": "17:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"}} > HTTP/1.0 200 OK > Content-Type: application/json > Content-Length: 17 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":true} - -8 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 400 False +{"success":true} + +8 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 400 False < PUT /update_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -168,13 +155,13 @@ < {"id_flight": "3", "flight": {"departure_time": 1600, "arrival_time": "17:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"}} > HTTP/1.0 400 BAD REQUEST > Content-Type: application/json -> Content-Length: 18 +> Content-Length: 77 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":false} - -9 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '1'}) 200 True +{"message":"id_flight not exist or flight format not valid","success":false} + +9 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '1'}) 200 True < DELETE /delete_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -189,11 +176,11 @@ > Content-Type: application/json > Content-Length: 17 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":true} - -10 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '4'}) 400 False +{"success":true} + +10 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '4'}) 400 False < DELETE /delete_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -206,13 +193,13 @@ < {"id_flight": "4"} > HTTP/1.0 400 BAD REQUEST > Content-Type: application/json -> Content-Length: 18 +> Content-Length: 50 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{"success":false} - -11 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +{"message":"id_flight not exist","success":false} + +11 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True < GET /show_flights HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -222,17 +209,65 @@ < > HTTP/1.0 200 OK -> Content-Type: text/html; charset=utf-8 -> Content-Length: 192 +> Content-Type: application/json +> Content-Length: 185 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sat, 02 Nov 2019 16:04:31 GMT +> +{"result":[{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} + +12 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '06:00', 'arrival_time': '08:00', 'travel_time': '02:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}) 200 True +< POST /new_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 138 +< Content-Type: application/json +< +< {"departure_time": "06:00", "arrival_time": "08:00", "travel_time": "02:00", "destination_airport": "Sheremetievo", "type_aircraft": "TU"} +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 33 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sat, 02 Nov 2019 16:04:31 GMT +> +{"id_flight":"3","success":true} + +13 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '11:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 200 True +< POST /new_flight HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< Content-Length: 133 +< Content-Type: application/json +< +< {"departure_time": "10:00", "arrival_time": "11:00", "travel_time": "01:00", "destination_airport": "Vnukovo", "type_aircraft": "TU"} +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 33 +> Server: Werkzeug/0.16.0 Python/3.6.8 +> Date: Sat, 02 Nov 2019 16:04:31 GMT +> +{"id_flight":"4","success":true} + +14 Urls(method='get', url='http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', headers=None, json=None) 200 True +< GET /show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo HTTP/1.1 +< Host: localhost:5000 +< User-Agent: python-requests/2.18.4 +< Accept-Encoding: gzip, deflate +< Accept: */* +< Connection: keep-alive +< + +> HTTP/1.0 200 OK +> Content-Type: application/json +> Content-Length: 342 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sun, 27 Oct 2019 18:05:03 GMT +> Date: Sat, 02 Nov 2019 16:04:31 GMT > -{ - "2": { - "departure_time": "16:00", - "arrival_time": "17:00", - "travel_time": "01:00", - "destination_airport": "Vnukovo", - "type_aircraft": "TU" - } -} +{"result":[{"flight":{"arrival_time":"08:00","departure_time":"06:00","destination_airport":"Sheremetievo","travel_time":"02:00","type_aircraft":"TU"},"id_flight":"3"},{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} + diff --git a/homeworks/homework_06_web/script.py b/homeworks/homework_06_web/script.py index 0b6716f8..c678df19 100644 --- a/homeworks/homework_06_web/script.py +++ b/homeworks/homework_06_web/script.py @@ -31,7 +31,7 @@ }, "update": { - "id_flight": "2", + "id_flight": "1", "flight": { "departure_time": "16:00", @@ -60,7 +60,23 @@ "bad delete": { "id_flight": "4", - } + }, + "third insert": + { + "departure_time": "06:00", + "arrival_time": "08:00", + "travel_time": "02:00", + "destination_airport": "Sheremetievo", + "type_aircraft": "TU" + }, + "forth insert": + { + "departure_time": "10:00", + "arrival_time": "11:00", + "travel_time": "01:00", + "destination_airport": "Vnukovo", + "type_aircraft": "TU" + }, } with open('request_dumps.txt', 'w') as f: @@ -77,6 +93,9 @@ Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["delete"]), Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["bad delete"]), Urls('get', 'http://localhost:5000/show_flights', None, None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["third insert"]), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["forth insert"]), + Urls('get', 'http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', None, None), ]): resp = requests.request( method=url.method, From 8fa16e909b38caf1de92bd027189cca1285ef950 Mon Sep 17 00:00:00 2001 From: tsapen Date: Sat, 2 Nov 2019 19:41:50 +0300 Subject: [PATCH 5/5] Update hw6 web --- homeworks/homework_06_web/data_processing.py | 1 - .../homework_06_web/flight_service.logging | 62 ++++----- homeworks/homework_06_web/request_dumps.txt | 120 +++++++++--------- homeworks/homework_06_web/script.py | 39 +++--- 4 files changed, 113 insertions(+), 109 deletions(-) diff --git a/homeworks/homework_06_web/data_processing.py b/homeworks/homework_06_web/data_processing.py index f7c76aac..46f83110 100644 --- a/homeworks/homework_06_web/data_processing.py +++ b/homeworks/homework_06_web/data_processing.py @@ -55,7 +55,6 @@ def select_all(sort_by, filter_field, filter_value): res.sort(key=lambda a: a["flight"][sort_by]) except BaseException: return None - print(res) return res diff --git a/homeworks/homework_06_web/flight_service.logging b/homeworks/homework_06_web/flight_service.logging index 867f1fb3..71b136f4 100644 --- a/homeworks/homework_06_web/flight_service.logging +++ b/homeworks/homework_06_web/flight_service.logging @@ -1,31 +1,31 @@ -2019-11-02 19:04:29,888 - werkzeug - INFO - * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) -2019-11-02 19:04:31,223 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0005, 'response': , 'http_status': 200} -2019-11-02 19:04:31,223 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights HTTP/1.1" 200 - -2019-11-02 19:04:31,228 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0014, 'response': , 'http_status': 200} -2019-11-02 19:04:31,229 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - -2019-11-02 19:04:31,236 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0039, 'response': , 'http_status': 200} -2019-11-02 19:04:31,236 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - -2019-11-02 19:04:31,240 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0006, 'response': , 'http_status': 400} -2019-11-02 19:04:31,240 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 400 - -2019-11-02 19:04:31,244 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0004, 'response': , 'http_status': 200} -2019-11-02 19:04:31,244 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights HTTP/1.1" 200 - -2019-11-02 19:04:31,247 - flask.app - INFO - {'url': 'http://localhost:5000/show_flight/1', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0002, 'response': , 'http_status': 200} -2019-11-02 19:04:31,247 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flight/1 HTTP/1.1" 200 - -2019-11-02 19:04:31,251 - flask.app - INFO - {'url': 'http://localhost:5000/show_flight/33', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0002, 'response': , 'http_status': 400} -2019-11-02 19:04:31,251 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flight/33 HTTP/1.1" 400 - -2019-11-02 19:04:31,256 - flask.app - INFO - {'url': 'http://localhost:5000/update_flight', 'args': {}, 'body': {'id_flight': '1', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, 'req_method': 'PUT', 'duration': 0.0019, 'response': , 'http_status': 200} -2019-11-02 19:04:31,257 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "PUT /update_flight HTTP/1.1" 200 - -2019-11-02 19:04:31,262 - flask.app - INFO - {'url': 'http://localhost:5000/update_flight', 'args': {}, 'body': {'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, 'req_method': 'PUT', 'duration': 0.0007, 'response': , 'http_status': 400} -2019-11-02 19:04:31,262 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "PUT /update_flight HTTP/1.1" 400 - -2019-11-02 19:04:31,266 - flask.app - INFO - {'url': 'http://localhost:5000/delete_flight', 'args': {}, 'body': {'id_flight': '1'}, 'req_method': 'DELETE', 'duration': 0.0005, 'response': , 'http_status': 200} -2019-11-02 19:04:31,266 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "DELETE /delete_flight HTTP/1.1" 200 - -2019-11-02 19:04:31,269 - flask.app - INFO - {'url': 'http://localhost:5000/delete_flight', 'args': {}, 'body': {'id_flight': '4'}, 'req_method': 'DELETE', 'duration': 0.0003, 'response': , 'http_status': 400} -2019-11-02 19:04:31,270 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "DELETE /delete_flight HTTP/1.1" 400 - -2019-11-02 19:04:31,275 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0007, 'response': , 'http_status': 200} -2019-11-02 19:04:31,276 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights HTTP/1.1" 200 - -2019-11-02 19:04:31,283 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '06:00', 'arrival_time': '08:00', 'travel_time': '02:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0012, 'response': , 'http_status': 200} -2019-11-02 19:04:31,283 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - -2019-11-02 19:04:31,288 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '10:00', 'arrival_time': '11:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.001, 'response': , 'http_status': 200} -2019-11-02 19:04:31,288 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "POST /new_flight HTTP/1.1" 200 - -2019-11-02 19:04:31,293 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', 'args': {'sort_by': 'arrival_time', 'filter_field': 'destination_airport', 'filter_value': 'Sheremetievo'}, 'body': None, 'req_method': 'GET', 'duration': 0.0005, 'response': , 'http_status': 200} -2019-11-02 19:04:31,293 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:04:31] "GET /show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo HTTP/1.1" 200 - +2019-11-02 19:40:13,980 - werkzeug - INFO - * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) +2019-11-02 19:40:15,725 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0004, 'response': , 'http_status': 200} +2019-11-02 19:40:15,725 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:40:15,734 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0016, 'response': , 'http_status': 200} +2019-11-02 19:40:15,735 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:40:15,742 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0009, 'response': , 'http_status': 200} +2019-11-02 19:40:15,742 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:40:15,749 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0015, 'response': , 'http_status': 400} +2019-11-02 19:40:15,750 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "POST /new_flight HTTP/1.1" 400 - +2019-11-02 19:40:15,762 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0006, 'response': , 'http_status': 200} +2019-11-02 19:40:15,765 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:40:15,774 - flask.app - INFO - {'url': 'http://localhost:5000/show_flight/1', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0004, 'response': , 'http_status': 200} +2019-11-02 19:40:15,774 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "GET /show_flight/1 HTTP/1.1" 200 - +2019-11-02 19:40:15,780 - flask.app - INFO - {'url': 'http://localhost:5000/show_flight/33', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0018, 'response': , 'http_status': 400} +2019-11-02 19:40:15,781 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "GET /show_flight/33 HTTP/1.1" 400 - +2019-11-02 19:40:15,790 - flask.app - INFO - {'url': 'http://localhost:5000/update_flight', 'args': {}, 'body': {'id_flight': '1', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, 'req_method': 'PUT', 'duration': 0.0011, 'response': , 'http_status': 200} +2019-11-02 19:40:15,790 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "PUT /update_flight HTTP/1.1" 200 - +2019-11-02 19:40:15,797 - flask.app - INFO - {'url': 'http://localhost:5000/update_flight', 'args': {}, 'body': {'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, 'req_method': 'PUT', 'duration': 0.003, 'response': , 'http_status': 400} +2019-11-02 19:40:15,797 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "PUT /update_flight HTTP/1.1" 400 - +2019-11-02 19:40:15,807 - flask.app - INFO - {'url': 'http://localhost:5000/delete_flight', 'args': {}, 'body': {'id_flight': '1'}, 'req_method': 'DELETE', 'duration': 0.001, 'response': , 'http_status': 200} +2019-11-02 19:40:15,808 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "DELETE /delete_flight HTTP/1.1" 200 - +2019-11-02 19:40:15,821 - flask.app - INFO - {'url': 'http://localhost:5000/delete_flight', 'args': {}, 'body': {'id_flight': '4'}, 'req_method': 'DELETE', 'duration': 0.0027, 'response': , 'http_status': 400} +2019-11-02 19:40:15,822 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "DELETE /delete_flight HTTP/1.1" 400 - +2019-11-02 19:40:15,827 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights', 'args': {}, 'body': None, 'req_method': 'GET', 'duration': 0.0006, 'response': , 'http_status': 200} +2019-11-02 19:40:15,830 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "GET /show_flights HTTP/1.1" 200 - +2019-11-02 19:40:15,842 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '06:00', 'arrival_time': '08:00', 'travel_time': '02:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0013, 'response': , 'http_status': 200} +2019-11-02 19:40:15,842 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:40:15,853 - flask.app - INFO - {'url': 'http://localhost:5000/new_flight', 'args': {}, 'body': {'departure_time': '10:00', 'arrival_time': '11:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, 'req_method': 'POST', 'duration': 0.0023, 'response': , 'http_status': 200} +2019-11-02 19:40:15,855 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "POST /new_flight HTTP/1.1" 200 - +2019-11-02 19:40:15,862 - flask.app - INFO - {'url': 'http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', 'args': {'sort_by': 'arrival_time', 'filter_field': 'destination_airport', 'filter_value': 'Sheremetievo'}, 'body': None, 'req_method': 'GET', 'duration': 0.0017, 'response': , 'http_status': 200} +2019-11-02 19:40:15,863 - werkzeug - INFO - 127.0.0.1 - - [02/Nov/2019 19:40:15] "GET /show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo HTTP/1.1" 200 - diff --git a/homeworks/homework_06_web/request_dumps.txt b/homeworks/homework_06_web/request_dumps.txt index c36da254..6d824d29 100644 --- a/homeworks/homework_06_web/request_dumps.txt +++ b/homeworks/homework_06_web/request_dumps.txt @@ -1,4 +1,4 @@ -0 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +0 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None, params=None) 200 True < GET /show_flights HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -11,11 +11,11 @@ > Content-Type: application/json > Content-Length: 29 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"result":[],"success":true} - -1 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 200 True +{"result":[],"success":true} + +1 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '13:00', 'travel_time': '03:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, params=None) 200 True < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -30,11 +30,11 @@ > Content-Type: application/json > Content-Length: 33 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"id_flight":"1","success":true} - -2 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}) 200 True +{"id_flight":"1","success":true} + +2 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '11:00', 'arrival_time': '12:00', 'travel_time': '01:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, params=None) 200 True < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -49,11 +49,11 @@ > Content-Type: application/json > Content-Length: 33 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"id_flight":"2","success":true} - -3 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 400 False +{"id_flight":"2","success":true} + +3 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '12:00', 'arrival_time': '25:00', 'travel_time': '02:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, params=None) 400 False < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -68,11 +68,11 @@ > Content-Type: application/json > Content-Length: 18 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"success":false} - -4 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +{"success":false} + +4 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None, params=None) 200 True < GET /show_flights HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -85,11 +85,11 @@ > Content-Type: application/json > Content-Length: 337 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"result":[{"flight":{"arrival_time":"13:00","departure_time":"10:00","destination_airport":"Vnukovo","travel_time":"03:00","type_aircraft":"TU"},"id_flight":"1"},{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} - -5 Urls(method='get', url='http://localhost:5000/show_flight/1', headers=None, json=None) 200 True +{"result":[{"flight":{"arrival_time":"13:00","departure_time":"10:00","destination_airport":"Vnukovo","travel_time":"03:00","type_aircraft":"TU"},"id_flight":"1"},{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} + +5 Urls(method='get', url='http://localhost:5000/show_flight/1', headers=None, json=None, params=None) 200 True < GET /show_flight/1 HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -102,11 +102,11 @@ > Content-Type: application/json > Content-Length: 151 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"flight":{"arrival_time":"13:00","departure_time":"10:00","destination_airport":"Vnukovo","travel_time":"03:00","type_aircraft":"TU"},"success":true} - -6 Urls(method='get', url='http://localhost:5000/show_flight/33', headers=None, json=None) 400 False +{"flight":{"arrival_time":"13:00","departure_time":"10:00","destination_airport":"Vnukovo","travel_time":"03:00","type_aircraft":"TU"},"success":true} + +6 Urls(method='get', url='http://localhost:5000/show_flight/33', headers=None, json=None, params=None) 400 False < GET /show_flight/33 HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -119,11 +119,11 @@ > Content-Type: application/json > Content-Length: 18 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"success":false} - -7 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '1', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 200 True +{"success":false} + +7 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '1', 'flight': {'departure_time': '16:00', 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, params=None) 200 True < PUT /update_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -138,11 +138,11 @@ > Content-Type: application/json > Content-Length: 17 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"success":true} - -8 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}) 400 False +{"success":true} + +8 Urls(method='put', url='http://localhost:5000/update_flight', headers=None, json={'id_flight': '3', 'flight': {'departure_time': 1600, 'arrival_time': '17:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}}, params=None) 400 False < PUT /update_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -157,11 +157,11 @@ > Content-Type: application/json > Content-Length: 77 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"message":"id_flight not exist or flight format not valid","success":false} - -9 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '1'}) 200 True +{"message":"id_flight not exist or flight format not valid","success":false} + +9 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '1'}, params=None) 200 True < DELETE /delete_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -176,11 +176,11 @@ > Content-Type: application/json > Content-Length: 17 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"success":true} - -10 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '4'}) 400 False +{"success":true} + +10 Urls(method='delete', url='http://localhost:5000/delete_flight', headers=None, json={'id_flight': '4'}, params=None) 400 False < DELETE /delete_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -195,11 +195,11 @@ > Content-Type: application/json > Content-Length: 50 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"message":"id_flight not exist","success":false} - -11 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None) 200 True +{"message":"id_flight not exist","success":false} + +11 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None, params=None) 200 True < GET /show_flights HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -212,11 +212,11 @@ > Content-Type: application/json > Content-Length: 185 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"result":[{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} - -12 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '06:00', 'arrival_time': '08:00', 'travel_time': '02:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}) 200 True +{"result":[{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} + +12 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '06:00', 'arrival_time': '08:00', 'travel_time': '02:00', 'destination_airport': 'Sheremetievo', 'type_aircraft': 'TU'}, params=None) 200 True < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -231,11 +231,11 @@ > Content-Type: application/json > Content-Length: 33 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"id_flight":"3","success":true} - -13 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '11:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}) 200 True +{"id_flight":"3","success":true} + +13 Urls(method='post', url='http://localhost:5000/new_flight', headers=None, json={'departure_time': '10:00', 'arrival_time': '11:00', 'travel_time': '01:00', 'destination_airport': 'Vnukovo', 'type_aircraft': 'TU'}, params=None) 200 True < POST /new_flight HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -250,11 +250,11 @@ > Content-Type: application/json > Content-Length: 33 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"id_flight":"4","success":true} - -14 Urls(method='get', url='http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', headers=None, json=None) 200 True +{"id_flight":"4","success":true} + +14 Urls(method='get', url='http://localhost:5000/show_flights', headers=None, json=None, params={'sort_by': 'arrival_time', 'filter_field': 'destination_airport', 'filter_value': 'Sheremetievo'}) 200 True < GET /show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo HTTP/1.1 < Host: localhost:5000 < User-Agent: python-requests/2.18.4 @@ -267,7 +267,7 @@ > Content-Type: application/json > Content-Length: 342 > Server: Werkzeug/0.16.0 Python/3.6.8 -> Date: Sat, 02 Nov 2019 16:04:31 GMT +> Date: Sat, 02 Nov 2019 16:40:15 GMT > -{"result":[{"flight":{"arrival_time":"08:00","departure_time":"06:00","destination_airport":"Sheremetievo","travel_time":"02:00","type_aircraft":"TU"},"id_flight":"3"},{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} - +{"result":[{"flight":{"arrival_time":"08:00","departure_time":"06:00","destination_airport":"Sheremetievo","travel_time":"02:00","type_aircraft":"TU"},"id_flight":"3"},{"flight":{"arrival_time":"12:00","departure_time":"11:00","destination_airport":"Sheremetievo","travel_time":"01:00","type_aircraft":"TU"},"id_flight":"2"}],"success":true} + diff --git a/homeworks/homework_06_web/script.py b/homeworks/homework_06_web/script.py index c678df19..1007e644 100644 --- a/homeworks/homework_06_web/script.py +++ b/homeworks/homework_06_web/script.py @@ -2,7 +2,7 @@ import requests from requests_toolbelt.utils.dump import dump_all -Urls = namedtuple('Urls', ['method', 'url', 'headers', 'json']) +Urls = namedtuple('Urls', ['method', 'url', 'headers', 'json', 'params']) jsons = { "first insert": @@ -78,29 +78,34 @@ "type_aircraft": "TU" }, } +params = { + "sort_by": "arrival_time", + "filter_field": "destination_airport", + "filter_value": "Sheremetievo"} with open('request_dumps.txt', 'w') as f: for index, url in enumerate([ - Urls('get', 'http://localhost:5000/show_flights', None, None), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["first insert"]), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["second insert"]), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["bad insert"]), - Urls('get', 'http://localhost:5000/show_flights', None, None), - Urls('get', 'http://localhost:5000/show_flight/1', None, None), - Urls('get', 'http://localhost:5000/show_flight/33', None, None), - Urls('put', 'http://localhost:5000/update_flight', None, jsons["update"]), - Urls('put', 'http://localhost:5000/update_flight', None, jsons["bad update"]), - Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["delete"]), - Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["bad delete"]), - Urls('get', 'http://localhost:5000/show_flights', None, None), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["third insert"]), - Urls('post', 'http://localhost:5000/new_flight', None, jsons["forth insert"]), - Urls('get', 'http://localhost:5000/show_flights?sort_by=arrival_time&filter_field=destination_airport&filter_value=Sheremetievo', None, None), + Urls('get', 'http://localhost:5000/show_flights', None, None, None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["first insert"], None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["second insert"], None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["bad insert"], None), + Urls('get', 'http://localhost:5000/show_flights', None, None, None), + Urls('get', 'http://localhost:5000/show_flight/1', None, None, None), + Urls('get', 'http://localhost:5000/show_flight/33', None, None, None), + Urls('put', 'http://localhost:5000/update_flight', None, jsons["update"], None), + Urls('put', 'http://localhost:5000/update_flight', None, jsons["bad update"], None), + Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["delete"], None), + Urls('delete', 'http://localhost:5000/delete_flight', None, jsons["bad delete"], None), + Urls('get', 'http://localhost:5000/show_flights', None, None, None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["third insert"], None), + Urls('post', 'http://localhost:5000/new_flight', None, jsons["forth insert"], None), + Urls('get', 'http://localhost:5000/show_flights', None, None, params), ]): resp = requests.request( method=url.method, url=url.url, headers=url.headers, - json=url.json) + json=url.json, + params=url.params) print(index, url, resp.status_code, resp.ok, file=f) print(dump_all(resp).decode('utf-8'), file=f)