From 5267e04fc7b8e91a59726f3caec9dffc876650d9 Mon Sep 17 00:00:00 2001 From: PabloTSuarez <160293077+PabloTSuarez@users.noreply.github.com> Date: Tue, 9 Apr 2024 01:36:08 +0000 Subject: [PATCH] Ejercicios_terminados_hasta_el_11 --- .learn/resets/01-what-is-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 +++ .learn/resets/09-array-of-blog-titles/app.py | 8 ++++++++ .learn/resets/10-get_post_tags/app.py | 8 ++++++++ .learn/resets/11-get_attachment_by_id/app.py | 7 +++++++ exercises/01-what-is-a-request/app.py | 4 ++-- exercises/02-random-status/app.py | 11 +++++++++++ exercises/03-response-body/app.py | 10 +++++++++- exercises/04-response-body-json/app.py | 7 ++++++- exercises/05-project-name/app.py | 6 +++++- exercises/06-project-list/app.py | 6 +++++- exercises/07-project-list-image/app.py | 7 ++++++- exercises/08-blog-post-author/app.py | 6 +++++- exercises/09-array-of-blog-titles/app.py | 9 +++++++-- exercises/10-get_post_tags/app.py | 10 +++++++++- exercises/11-get_attachment_by_id/app.py | 11 ++++++++++- 22 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 .learn/resets/01-what-is-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-array-of-blog-titles/app.py create mode 100644 .learn/resets/10-get_post_tags/app.py create mode 100644 .learn/resets/11-get_attachment_by_id/app.py diff --git a/.learn/resets/01-what-is-a-request/app.py b/.learn/resets/01-what-is-a-request/app.py new file mode 100644 index 0000000..7b78511 --- /dev/null +++ b/.learn/resets/01-what-is-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..37cdac0 --- /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" \ 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..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..a471294 --- /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..a471294 --- /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..a471294 --- /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..a471294 --- /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-array-of-blog-titles/app.py b/.learn/resets/09-array-of-blog-titles/app.py new file mode 100644 index 0000000..e464bad --- /dev/null +++ b/.learn/resets/09-array-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..0889c24 --- /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..26274ff --- /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/exercises/01-what-is-a-request/app.py b/exercises/01-what-is-a-request/app.py index 7b78511..6d39d8c 100644 --- a/exercises/01-what-is-a-request/app.py +++ b/exercises/01-what-is-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 diff --git a/exercises/02-random-status/app.py b/exercises/02-random-status/app.py index d9ef815..c116d91 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") + +if response.status_code == 404: + print("The URL you asked is not found") +elif response.status_code == 503: + print("Unavailable right now") +elif response.status_code == 200: + print("Everything went perfect") +elif response.status_code == 400: + print("Something is wrong on the request params") +else: + print("anything") \ No newline at end of file diff --git a/exercises/03-response-body/app.py b/exercises/03-response-body/app.py index 37cdac0..a9b7035 100644 --- a/exercises/03-response-body/app.py +++ b/exercises/03-response-body/app.py @@ -1,3 +1,11 @@ import requests -url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" \ No newline at end of file +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..735cf3f 100644 --- a/exercises/04-response-body-json/app.py +++ b/exercises/04-response-body-json/app.py @@ -1,4 +1,9 @@ import requests response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php") -print(response.text) \ No newline at end of file +#print(response.text) + +dict = response.json() +#print(dict) + +print(f"Current time: {dict['hours']} hrs {dict['minutes'] } min and {dict['seconds']} sec") \ No newline at end of file diff --git a/exercises/05-project-name/app.py b/exercises/05-project-name/app.py index a471294..d57a67e 100644 --- a/exercises/05-project-name/app.py +++ b/exercises/05-project-name/app.py @@ -1,3 +1,7 @@ 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') + +print(response.json()['name']) \ No newline at end of file diff --git a/exercises/06-project-list/app.py b/exercises/06-project-list/app.py index a471294..cb0da96 100644 --- a/exercises/06-project-list/app.py +++ b/exercises/06-project-list/app.py @@ -1,3 +1,7 @@ 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') + +print(response.json()[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 a471294..bcc052c 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 + +response = requests.get('https://assets.breatheco.de/apis/fake/sample/project_list.php') + +#print(response.json()) +print(response.json()[-1]['images'][-1]) diff --git a/exercises/08-blog-post-author/app.py b/exercises/08-blog-post-author/app.py index a471294..dcb033c 100644 --- a/exercises/08-blog-post-author/app.py +++ b/exercises/08-blog-post-author/app.py @@ -1,3 +1,7 @@ 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') + +print(response.json()['posts'][0]['author']['name']) \ No newline at end of file diff --git a/exercises/09-array-of-blog-titles/app.py b/exercises/09-array-of-blog-titles/app.py index e464bad..e7ceeb6 100644 --- a/exercises/09-array-of-blog-titles/app.py +++ b/exercises/09-array-of-blog-titles/app.py @@ -2,7 +2,12 @@ def get_titles(): # your code here - return None + titles = [] + response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') + for resp in response.json()['posts']: + titles.append(resp['title']) + return titles + +print(get_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 0889c24..13605ba 100644 --- a/exercises/10-get_post_tags/app.py +++ b/exercises/10-get_post_tags/app.py @@ -2,7 +2,15 @@ def get_post_tags(post_id): # your code here - return None + response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') + json = response.json()['posts'] + for post in json: + if post['id'] == post_id: + tags = post['tags'] + break + else: + tags = None + 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 26274ff..ef3ce12 100644 --- a/exercises/11-get_attachment_by_id/app.py +++ b/exercises/11-get_attachment_by_id/app.py @@ -2,6 +2,15 @@ def get_attachment_by_id(attachment_id): # your code here - return None + response = requests.get('https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php') + json = response.json()['posts'] + for post in json: + for at in post['attachment']: + if at ['id'] == attachment_id: + at_r = at + break + else: + at_r = None + return at_r print(get_attachment_by_id(137)) \ No newline at end of file