From a234fd354ab5fcd2d6a87d259ee4c02e6fdf9b2d Mon Sep 17 00:00:00 2001 From: remelop03 Date: 2025年5月24日 17:42:34 +0000 Subject: [PATCH 1/2] exercise_08 --- .learn/resets/01-creating-a-request/app.py | 7 +++++++ .learn/resets/02-random-status/app.py | 3 +++ .learn/resets/03-response-body/app.py | 3 +++ .learn/resets/04-response-body-json/app.py | 4 ++++ .learn/resets/05-project-name/app.py | 3 +++ .learn/resets/06-project-list/app.py | 3 +++ .learn/resets/07-project-list-image/app.py | 3 +++ .learn/resets/08-blog-post-author/app.py | 3 +++ exercises/01-creating-a-request/app.py | 6 ++---- exercises/02-random-status/app.py | 15 +++++++++++++-- exercises/03-response-body/app.py | 6 ++++++ exercises/04-response-body-json/app.py | 10 +++++++--- exercises/05-project-name/app.py | 8 +++++++- exercises/06-project-list/app.py | 7 ++++++- exercises/07-project-list-image/app.py | 7 ++++++- 15 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 .learn/resets/01-creating-a-request/app.py create mode 100644 .learn/resets/02-random-status/app.py create mode 100644 .learn/resets/03-response-body/app.py create mode 100644 .learn/resets/04-response-body-json/app.py create mode 100644 .learn/resets/05-project-name/app.py create mode 100644 .learn/resets/06-project-list/app.py create mode 100644 .learn/resets/07-project-list-image/app.py create mode 100644 .learn/resets/08-blog-post-author/app.py diff --git a/.learn/resets/01-creating-a-request/app.py b/.learn/resets/01-creating-a-request/app.py new file mode 100644 index 0000000..7b78511 --- /dev/null +++ b/.learn/resets/01-creating-a-request/app.py @@ -0,0 +1,7 @@ +import requests + +url = "https://assets.breatheco.de/apis/fake/sample/404-example.php" +# url = "https://assets.breatheco.de/apis/fake/sample/hello.php" +response = requests.get(url) + +print("The response status is: "+str(response.status_code)) \ No newline at end of file diff --git a/.learn/resets/02-random-status/app.py b/.learn/resets/02-random-status/app.py new file mode 100644 index 0000000..d9ef815 --- /dev/null +++ b/.learn/resets/02-random-status/app.py @@ -0,0 +1,3 @@ +import requests + +response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php") diff --git a/.learn/resets/03-response-body/app.py b/.learn/resets/03-response-body/app.py new file mode 100644 index 0000000..66b2f6b --- /dev/null +++ b/.learn/resets/03-response-body/app.py @@ -0,0 +1,3 @@ +import requests + +url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" diff --git a/.learn/resets/04-response-body-json/app.py b/.learn/resets/04-response-body-json/app.py new file mode 100644 index 0000000..11ecbd8 --- /dev/null +++ b/.learn/resets/04-response-body-json/app.py @@ -0,0 +1,4 @@ +import requests + +response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php") +print(response.text) \ No newline at end of file diff --git a/.learn/resets/05-project-name/app.py b/.learn/resets/05-project-name/app.py new file mode 100644 index 0000000..0ca5c86 --- /dev/null +++ b/.learn/resets/05-project-name/app.py @@ -0,0 +1,3 @@ +import requests + +# Your code here \ No newline at end of file diff --git a/.learn/resets/06-project-list/app.py b/.learn/resets/06-project-list/app.py new file mode 100644 index 0000000..0ca5c86 --- /dev/null +++ b/.learn/resets/06-project-list/app.py @@ -0,0 +1,3 @@ +import requests + +# Your code here \ No newline at end of file diff --git a/.learn/resets/07-project-list-image/app.py b/.learn/resets/07-project-list-image/app.py new file mode 100644 index 0000000..0ca5c86 --- /dev/null +++ b/.learn/resets/07-project-list-image/app.py @@ -0,0 +1,3 @@ +import requests + +# Your code here \ No newline at end of file diff --git a/.learn/resets/08-blog-post-author/app.py b/.learn/resets/08-blog-post-author/app.py new file mode 100644 index 0000000..0ca5c86 --- /dev/null +++ b/.learn/resets/08-blog-post-author/app.py @@ -0,0 +1,3 @@ +import requests + +# Your code here \ No newline at end of file diff --git a/exercises/01-creating-a-request/app.py b/exercises/01-creating-a-request/app.py index 7b78511..c83d4ff 100644 --- a/exercises/01-creating-a-request/app.py +++ b/exercises/01-creating-a-request/app.py @@ -1,7 +1,5 @@ import requests -url = "https://assets.breatheco.de/apis/fake/sample/404-example.php" -# url = "https://assets.breatheco.de/apis/fake/sample/hello.php" +url = "https://assets.breatheco.de/apis/fake/sample/hello.php" response = requests.get(url) - -print("The response status is: "+str(response.status_code)) \ No newline at end of file +print(response.status_code) \ No newline at end of file diff --git a/exercises/02-random-status/app.py b/exercises/02-random-status/app.py index d9ef815..0ae8584 100644 --- a/exercises/02-random-status/app.py +++ b/exercises/02-random-status/app.py @@ -1,3 +1,14 @@ import requests - -response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php") +url = 'https://assets.breatheco.de/apis/fake/sample/random-status.php' +response = requests.get(url) +status = response.status_code +if status == 404: + print('The URL you asked for is not found') +elif status == 503: + print('Unavailable right now') +elif status == 200: + print('Everything went perfect') +elif status == 400: + print('Something is wrong with the request params') +else: + print('Unknown status code') diff --git a/exercises/03-response-body/app.py b/exercises/03-response-body/app.py index 66b2f6b..97317fb 100644 --- a/exercises/03-response-body/app.py +++ b/exercises/03-response-body/app.py @@ -1,3 +1,9 @@ import requests url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" +response = requests.get(url) +status = response.status_code +if status == 200: + print(response.text) +else: + print("Something went wrong") \ No newline at end of file diff --git a/exercises/04-response-body-json/app.py b/exercises/04-response-body-json/app.py index 11ecbd8..900d737 100644 --- a/exercises/04-response-body-json/app.py +++ b/exercises/04-response-body-json/app.py @@ -1,4 +1,8 @@ import requests - -response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php") -print(response.text) \ No newline at end of file +url = "https://assets.breatheco.de/apis/fake/sample/time.php" +response = requests.get(url) +dict = response.json() +hour = dict["hours"] +min = dict["minutes"] +sec = dict["seconds"] +print(f"Current time: {hour} hrs {min} min and {sec} sec") \ No newline at end of file diff --git a/exercises/05-project-name/app.py b/exercises/05-project-name/app.py index 0ca5c86..ad208dc 100644 --- a/exercises/05-project-name/app.py +++ b/exercises/05-project-name/app.py @@ -1,3 +1,9 @@ import requests -# Your code here \ No newline at end of file +url = "https://assets.breatheco.de/apis/fake/sample/project1.php" +response = requests.get(url) + +# Your code here +dict = response.json() +name = dict["name"] +print(name) \ No newline at end of file diff --git a/exercises/06-project-list/app.py b/exercises/06-project-list/app.py index 0ca5c86..e43b6b2 100644 --- a/exercises/06-project-list/app.py +++ b/exercises/06-project-list/app.py @@ -1,3 +1,8 @@ import requests -# Your code here \ No newline at end of file +# Your code here +url = "https://assets.breatheco.de/apis/fake/sample/project_list.php" +response = requests.get(url) +project_list = response.json() +second_name = project_list[1]["name"] +print(second_name) \ No newline at end of file diff --git a/exercises/07-project-list-image/app.py b/exercises/07-project-list-image/app.py index 0ca5c86..2b9dbb4 100644 --- a/exercises/07-project-list-image/app.py +++ b/exercises/07-project-list-image/app.py @@ -1,3 +1,8 @@ import requests -# Your code here \ No newline at end of file +# Your code here +url = "https://assets.breatheco.de/apis/fake/sample/project_list.php" +response = requests.get(url) +project_list = response.json() +image_url = project_list[2]["images"][2] +print(image_url) \ No newline at end of file From 2e4b17b9b77463c408996e0ff17a1deb8db0f83a Mon Sep 17 00:00:00 2001 From: remelop03 Date: 2025年5月24日 18:09:45 +0000 Subject: [PATCH 2/2] exercise_09 --- .learn/resets/09-list-of-blog-titles/app.py | 8 ++++++++ .learn/resets/10-get-post-tags/app.py | 8 ++++++++ exercises/08-blog-post-author/app.py | 16 +++++++++++++++- exercises/09-list-of-blog-titles/app.py | 12 ++++++++---- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 .learn/resets/09-list-of-blog-titles/app.py create mode 100644 .learn/resets/10-get-post-tags/app.py diff --git a/.learn/resets/09-list-of-blog-titles/app.py b/.learn/resets/09-list-of-blog-titles/app.py new file mode 100644 index 0000000..cc536a8 --- /dev/null +++ b/.learn/resets/09-list-of-blog-titles/app.py @@ -0,0 +1,8 @@ +import requests + +def get_titles(): + # Your code here + return None + + +print(get_titles()) \ No newline at end of file diff --git a/.learn/resets/10-get-post-tags/app.py b/.learn/resets/10-get-post-tags/app.py new file mode 100644 index 0000000..ff6d142 --- /dev/null +++ b/.learn/resets/10-get-post-tags/app.py @@ -0,0 +1,8 @@ +import requests + +def get_post_tags(post_id): + # Your code here + return None + + +print(get_post_tags(146)) \ No newline at end of file diff --git a/exercises/08-blog-post-author/app.py b/exercises/08-blog-post-author/app.py index 0ca5c86..4de9258 100644 --- a/exercises/08-blog-post-author/app.py +++ b/exercises/08-blog-post-author/app.py @@ -1,3 +1,17 @@ import requests -# Your code here \ No newline at end of file +# Your code here +url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php" +response = requests.get(url) +data = response.json() + +# Getting the first post +first_post = data["posts"][0] + +# Getting the author dictionary +author_dict = first_post["author"] + +# Getting the author name +author_name = author_dict["name"] + +print(author_name) \ No newline at end of file diff --git a/exercises/09-list-of-blog-titles/app.py b/exercises/09-list-of-blog-titles/app.py index cc536a8..d9891d4 100644 --- a/exercises/09-list-of-blog-titles/app.py +++ b/exercises/09-list-of-blog-titles/app.py @@ -1,8 +1,12 @@ import requests -def get_titles(): +def get_titles(web_page): # Your code here - return None + titles = [] + response = requests.get(url) + data = response.json() + post = data["posts"] + return post - -print(get_titles()) \ No newline at end of file +url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php" +print(get_titles(url)) \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /