From f292b0e31a1f0eb1be1e062797944d59a5893d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ignacio=20Ibarra=20Lemp?= Date: 2025年2月24日 17:11:16 +0000 Subject: [PATCH 1/2] Exercises 1 to 8 --- .learn/resets/01-creating-a-request/app.py | 7 +++++++ .learn/resets/02-random-status/app.py | 16 ++++++++++++++++ .learn/resets/03-response-body/app.py | 10 ++++++++++ .learn/resets/04-response-body-json/app.py | 8 ++++++++ .learn/resets/05-project-name/app.py | 11 +++++++++++ .learn/resets/06-project-list/app.py | 6 ++++++ .learn/resets/07-project-list-image/app.py | 6 ++++++ .learn/resets/08-blog-post-author/app.py | 3 +++ .learn/resets/09-list-of-blog-titles/app.py | 8 ++++++++ exercises/01-creating-a-request/app.py | 6 +++--- exercises/02-random-status/app.py | 13 +++++++++++++ exercises/03-response-body/app.py | 7 +++++++ exercises/04-response-body-json/app.py | 6 +++++- exercises/05-project-name/app.py | 10 +++++++++- exercises/06-project-list/app.py | 5 ++++- exercises/07-project-list-image/app.py | 5 ++++- exercises/08-blog-post-author/app.py | 5 ++++- 17 files changed, 124 insertions(+), 8 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 create mode 100644 .learn/resets/09-list-of-blog-titles/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..7e35b0e --- /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)) diff --git a/.learn/resets/02-random-status/app.py b/.learn/resets/02-random-status/app.py new file mode 100644 index 0000000..28ab754 --- /dev/null +++ b/.learn/resets/02-random-status/app.py @@ -0,0 +1,16 @@ +import requests + +response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php") + +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") \ No newline at end of file diff --git a/.learn/resets/03-response-body/app.py b/.learn/resets/03-response-body/app.py new file mode 100644 index 0000000..9409dea --- /dev/null +++ b/.learn/resets/03-response-body/app.py @@ -0,0 +1,10 @@ +import requests + +url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" + +response = requests.get(url) + +if response.status_code == 200: + print(response.text) +else: + print("Something went wrong") \ No newline at end of file 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..d28124e --- /dev/null +++ b/.learn/resets/04-response-body-json/app.py @@ -0,0 +1,8 @@ +import requests + +response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php") +time_dict = response.json() +hrs = time_dict['hours'] +mins = time_dict['minutes'] +sec = time_dict['seconds'] +print(f'Current time: {hrs} hrs {mins} min and {sec} sec') \ 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..0e44b3a --- /dev/null +++ b/.learn/resets/05-project-name/app.py @@ -0,0 +1,11 @@ +import requests + +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project1.php') + +if response.status_code == 200: + response_dict = response.json() + name = response_dict['name'] + print(name) +else: + print("Data extraction failed") \ 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..9dea399 --- /dev/null +++ b/.learn/resets/06-project-list/app.py @@ -0,0 +1,6 @@ +import requests + +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php') +response_dict = response.json() +print(response_dict[1]['name']) \ 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..9648d5d --- /dev/null +++ b/.learn/resets/07-project-list-image/app.py @@ -0,0 +1,6 @@ +import requests + +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php') +response_dict = response.json() +print(response_dict[-1]['images'][-1]) \ 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/.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/exercises/01-creating-a-request/app.py b/exercises/01-creating-a-request/app.py index 7b78511..7e35b0e 100644 --- a/exercises/01-creating-a-request/app.py +++ b/exercises/01-creating-a-request/app.py @@ -1,7 +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" +# 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 +print("The response status is: "+str(response.status_code)) diff --git a/exercises/02-random-status/app.py b/exercises/02-random-status/app.py index d9ef815..28ab754 100644 --- a/exercises/02-random-status/app.py +++ b/exercises/02-random-status/app.py @@ -1,3 +1,16 @@ import requests response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php") + +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") \ No newline at end of file diff --git a/exercises/03-response-body/app.py b/exercises/03-response-body/app.py index 66b2f6b..9409dea 100644 --- a/exercises/03-response-body/app.py +++ b/exercises/03-response-body/app.py @@ -1,3 +1,10 @@ import requests url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" + +response = requests.get(url) + +if response.status_code == 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..d28124e 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 +time_dict = response.json() +hrs = time_dict['hours'] +mins = time_dict['minutes'] +sec = time_dict['seconds'] +print(f'Current time: {hrs} hrs {mins} 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..0e44b3a 100644 --- a/exercises/05-project-name/app.py +++ b/exercises/05-project-name/app.py @@ -1,3 +1,11 @@ import requests -# Your code here \ No newline at end of file +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project1.php') + +if response.status_code == 200: + response_dict = response.json() + name = response_dict['name'] + print(name) +else: + print("Data extraction failed") \ No newline at end of file diff --git a/exercises/06-project-list/app.py b/exercises/06-project-list/app.py index 0ca5c86..9dea399 100644 --- a/exercises/06-project-list/app.py +++ b/exercises/06-project-list/app.py @@ -1,3 +1,6 @@ import requests -# Your code here \ No newline at end of file +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php') +response_dict = response.json() +print(response_dict[1]['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..9648d5d 100644 --- a/exercises/07-project-list-image/app.py +++ b/exercises/07-project-list-image/app.py @@ -1,3 +1,6 @@ import requests -# Your code here \ No newline at end of file +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php') +response_dict = response.json() +print(response_dict[-1]['images'][-1]) \ 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..371f7de 100644 --- a/exercises/08-blog-post-author/app.py +++ b/exercises/08-blog-post-author/app.py @@ -1,3 +1,6 @@ import requests -# Your code here \ No newline at end of file +# Your code here +response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') +response_dict = response.json() +print(response_dict['posts'][0]['author']['name']) From 516e595654026980bca17130b59079615de2ad2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ignacio=20Ibarra=20Lemp?= Date: 2025年2月24日 19:50:55 +0000 Subject: [PATCH 2/2] Submission 24/02 --- .learn/resets/10-get-post-tags/app.py | 8 ++++++++ .learn/resets/11-get-attachment-by-id/app.py | 7 +++++++ .learn/resets/12-post-request/app.py | 3 +++ .learn/resets/13-post-request-body/app.py | 4 ++++ exercises/09-list-of-blog-titles/app.py | 8 +++++++- exercises/10-get-post-tags/app.py | 8 +++++++- exercises/11-get-attachment-by-id/app.py | 8 +++++++- exercises/12-post-request/app.py | 8 +++++++- exercises/13-post-request-body/app.py | 12 +++++++++++- 9 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 .learn/resets/10-get-post-tags/app.py create mode 100644 .learn/resets/11-get-attachment-by-id/app.py create mode 100644 .learn/resets/12-post-request/app.py create mode 100644 .learn/resets/13-post-request-body/app.py 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/.learn/resets/11-get-attachment-by-id/app.py b/.learn/resets/11-get-attachment-by-id/app.py new file mode 100644 index 0000000..3571d84 --- /dev/null +++ b/.learn/resets/11-get-attachment-by-id/app.py @@ -0,0 +1,7 @@ +import requests + +def get_attachment_by_id(attachment_id): + # Your code here + return None + +print(get_attachment_by_id(137)) \ No newline at end of file diff --git a/.learn/resets/12-post-request/app.py b/.learn/resets/12-post-request/app.py new file mode 100644 index 0000000..0ca5c86 --- /dev/null +++ b/.learn/resets/12-post-request/app.py @@ -0,0 +1,3 @@ +import requests + +# Your code here \ No newline at end of file diff --git a/.learn/resets/13-post-request-body/app.py b/.learn/resets/13-post-request-body/app.py new file mode 100644 index 0000000..df545c3 --- /dev/null +++ b/.learn/resets/13-post-request-body/app.py @@ -0,0 +1,4 @@ +import requests + +response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php") +print(response.text) \ 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..616b307 100644 --- a/exercises/09-list-of-blog-titles/app.py +++ b/exercises/09-list-of-blog-titles/app.py @@ -2,7 +2,13 @@ def get_titles(): # Your code here - return None + titles = [] + response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') + response_dict = response.json() + for post in response_dict['posts']: + title = post['title'] + titles.append(title) + return titles print(get_titles()) \ No newline at end of file diff --git a/exercises/10-get-post-tags/app.py b/exercises/10-get-post-tags/app.py index ff6d142..70404fa 100644 --- a/exercises/10-get-post-tags/app.py +++ b/exercises/10-get-post-tags/app.py @@ -2,7 +2,13 @@ def get_post_tags(post_id): # Your code here - return None + tags = [] + response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') + response_dict = response.json() + for post in response_dict['posts']: + if post['id'] == post_id: + tags = post['tags'] + return tags print(get_post_tags(146)) \ No newline at end of file diff --git a/exercises/11-get-attachment-by-id/app.py b/exercises/11-get-attachment-by-id/app.py index 3571d84..be388b4 100644 --- a/exercises/11-get-attachment-by-id/app.py +++ b/exercises/11-get-attachment-by-id/app.py @@ -2,6 +2,12 @@ def get_attachment_by_id(attachment_id): # Your code here - return None + attachments_list = [] + response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') + response_dict = response.json() + for post in response_dict['posts']: + attachments = post['attachments'] + if len(attachments)> 0 and attachments[0]['id'] == attachment_id: + return attachments[0]['title'] print(get_attachment_by_id(137)) \ No newline at end of file diff --git a/exercises/12-post-request/app.py b/exercises/12-post-request/app.py index 0ca5c86..08d2ec0 100644 --- a/exercises/12-post-request/app.py +++ b/exercises/12-post-request/app.py @@ -1,3 +1,9 @@ import requests -# Your code here \ No newline at end of file +# Your code here +url = 'https://assets.breatheco.de/apis/fake/sample/post.php' +my_obj = {'somekey': 'somevalue'} + +x = requests.post(url, json = my_obj) + +print(x.text) \ No newline at end of file diff --git a/exercises/13-post-request-body/app.py b/exercises/13-post-request-body/app.py index df545c3..bf4c5a6 100644 --- a/exercises/13-post-request-body/app.py +++ b/exercises/13-post-request-body/app.py @@ -1,4 +1,14 @@ import requests -response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php") +url = "https://assets.breatheco.de/apis/fake/sample/save-project-json.php" + +my_obj = { + "id": 2323, + "title": "Very big project" + } + +headers = {'Content-Type': 'application/json'} + +response = requests.post(url, json = my_obj, headers=headers) + print(response.text) \ No newline at end of file

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