-
Notifications
You must be signed in to change notification settings - Fork 14
[#H17] (Added task 1,2,3) #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. если этот файл твоего хранилища и он не нужен для задачи - то не добавляй такое в коммит |
||
| 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() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
чето много очень строчек в конце файла, уменьши до 1 пустой