Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Shops/building_materials_store/app/Homework/flask_hw/1_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Сделайте так, чтобы при переходе на страницу
localhost:5000/hello/alex/age/100
На странице повлялся текст:
Hello Alex! Your age is 100!
А при переходе на
localhost:5000/hello/bob/age/1
Hello Bob! Your age is 1!
"""

from flask import Flask


app = Flask(__name__)


@app.route("/hello/<string:name>/age/<int:age>")
def index(name: str, age: int):
return f"Hello {name}! Your age is {age}!"


app.run(port=5000)




Comment on lines +23 to +26
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

чето много очень строчек в конце файла, уменьши до 1 пустой

65 changes: 65 additions & 0 deletions Shops/building_materials_store/app/Homework/flask_hw/2_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Запустите приложение, посмотрите, как оно сейчас работает
Сделайте так, чтобы при переходе по
localhost:5000/cars
Выводился json следующего формата:
{
"cars_number": 25,
"cars": [
{
"id": 101068323,
"price_usd": 22300,
"brand": "Nissan",
"model": "Leaf",
"generation": "II",
"year": "2017",
"rain_detector": true,
"interior_material": "ткань",
"created_advert": "2022-05-01T18:59:04+0000"
},
...
]
}
(extra) Дабавьте фильтрацию через адресную строку по всем этим параметрам.
"""

import json
from flask import Flask
from flask import jsonify


app = Flask(__name__)


def get_cars():
with open("2_task_storage.json") as file:
data = json.load(file)
return data


@app.route("/cars")
def get_cars_view():
cars = get_cars()
return jsonify(cars)


#extra In progress
# @app.route("/cars/<option>", methods=["GET"])
# def get_options(option):
# response = get_cars().get('cars')
#
# id = request.args.get("id")
# price_usd = request.args.get("price_usd")
# brand = request.args.get("brand")
# model = request.args.get("model")
# generation = request.args.get("generation")
# year = request.args.get("year")
# rain_detector = request.args.get("rain_detector")
# interior_material = request.args.get("interior_material")
# created_advert = request.args.get("created_advert")
# .......
# response = UserStorage('1.json').find_users(name=name, job=job)
# return jsonify(list(response))
Comment on lines +46 to +62
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ойойой комменты не пуш...



app.run(port=5000)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"cars_number": 25,
"cars": [
{
"id": 101068323,
"price_usd": 22300,
"brand": "Nissan",
"model": "Leaf",
"generation": "II",
"year": "2017",
"rain_detector": true,
"interior_material": "ткань",
"created_advert": "2022-05-01T18:59:04+0000"
}

]
}
Comment on lines +1 to +17
Copy link
Owner

@Chudopal Chudopal Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если этот файл твоего хранилища и он не нужен для задачи - то не добавляй такое в коммит

54 changes: 54 additions & 0 deletions Shops/building_materials_store/app/Homework/flask_hw/3_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Небольшое приложение расписания.
Запустите приложение, перейдите на
localhost:5000/schedule/monday/06-06-2022
Посмотрите что будет, поймите как это работает.
Переделайте приложение так, чтобы при переходе на
localhost:5000/schedule/monday/06-06-2022
Выводилось именно расписание на понедельник 6го июня 2022 года
Как работают шаблоны фласк, можно почитать тут:
- https://flask-russian-docs.readthedocs.io/ru/latest/tutorial/templates.html
"""

import json
from typing import List
from typing import Dict
from flask import Flask
from flask import render_template

app = Flask(__name__)


class ScheduleStorage:

def __init__(self, file_path: str, data_path: tuple) -> None:
self.file_path = file_path
self.data_path = data_path
self.data = self._get_data(self._read_file())

def _read_file(self) -> Dict:
with open(self.file_path) as file:
base_data = json.load(file)
return base_data

def _get_data(self, base_data) -> List:
result = base_data
for step in self.data_path:
result = result.get(step)
return result

def get_data(self) -> List:
return self.data


schedule_storage = ScheduleStorage("storage.json", ["3_task", "schedule"])


@app.route("/schedule/<string:week_day>/<string:date>")
def get_schedule(week_day, date):
date = f"{week_day}, {date}"
data = schedule_storage.get_data().get('monday')[0].items()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, по дню недели верно, но фильтрация по дате отсуствует, надо добавить

return render_template("3_task/schedule.html", data=data, date=date)


app.run(port=5000)
Loading