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..de2b192 --- /dev/null +++ b/.learn/resets/01-what-is-a-request/app.py @@ -0,0 +1,6 @@ +import requests + +url = "https://assets.breatheco.de/apis/fake/sample/404-example.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/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/.vscode/settings.json b/.vscode/settings.json index 2f5ad94..0dbc76c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,7 @@ "editor.minimap.enabled": false, "workbench.editorAssociations": { "*.md": "vscode.markdown.preview.editor" - } + }, + "python.analysis.autoImportCompletions": true, + "python.analysis.typeCheckingMode": "basic" } \ 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 de2b192..0fd3e88 100644 --- a/exercises/01-what-is-a-request/app.py +++ b/exercises/01-what-is-a-request/app.py @@ -1,6 +1,6 @@ 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 +print(f"The response status is: {response.status_code}") #El test está mal \ No newline at end of file diff --git a/exercises/01-what-is-a-request/test.py b/exercises/01-what-is-a-request/test.py index 64f7279..9b0d2e6 100644 --- a/exercises/01-what-is-a-request/test.py +++ b/exercises/01-what-is-a-request/test.py @@ -5,5 +5,6 @@ def test_url(app): with patch('requests.get') as mock_request: app() - url = "https://assets.breatheco.de/apis/fake/sample/hello.php" + url = "https://assets.breatheco.de/apis/fake/sample/hello.php +" assert mock_request.call_args.args[0] == url \ No newline at end of file diff --git a/exercises/02-random-status/app.py b/exercises/02-random-status/app.py index d9ef815..ff8b6de 100644 --- a/exercises/02-random-status/app.py +++ b/exercises/02-random-status/app.py @@ -1,3 +1,17 @@ import requests response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php") + +def error_code (status): + if (status == 200): + return "Everything went perfect\n" + elif (status == 400): + return "Something is wrong on the request params\n" + elif (status == 404): + return "The URL you asked is not found\n" + elif (status == 503): + return "Unavailable right now\n" + +# TEST FALLAN AUNQUE LAS RESPUETAS SEAN LA CORRECTAS: SyntaxError: invalid decimal literal + +print(error_code(response.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 37cdac0..f43f95d 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" \ 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..f485f14 100644 --- a/exercises/04-response-body-json/app.py +++ b/exercises/04-response-body-json/app.py @@ -1,4 +1,5 @@ import requests -response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php") -print(response.text) \ No newline at end of file +response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php").json() + +print(f"Current time: {response['hours']} hrs {response['minutes']} and {response['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..ed9687a 100644 --- a/exercises/05-project-name/app.py +++ b/exercises/05-project-name/app.py @@ -1,3 +1,8 @@ +from urllib import request, response import requests -# your code here \ No newline at end of file +# your code here +url = "https://assets.breatheco.de/apis/fake/sample/project1.php" +resp = requests.get(url).json() + +print(resp['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..a2d4baa 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 +url = "https://assets.breatheco.de/apis/fake/sample/project_list.php" +resp = requests.get(url).json() + +print(resp[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..075c863 100644 --- a/exercises/07-project-list-image/app.py +++ b/exercises/07-project-list-image/app.py @@ -1,3 +1,7 @@ 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" +resp = requests.get(url).json() + +print(resp[-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 a471294..b612731 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 +url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php" +resp = requests.get(url).json() + +print(resp['posts'][1]['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..8117d2a 100644 --- a/exercises/09-array-of-blog-titles/app.py +++ b/exercises/09-array-of-blog-titles/app.py @@ -1,8 +1,15 @@ import requests + def get_titles(): - # your code here - return None + arr_titles = [] + url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php" + resp = requests.get(url).json() + + for post in resp['posts']: + arr_titles.append(post['title'])\ + + return arr_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..e860179 100644 --- a/exercises/10-get_post_tags/app.py +++ b/exercises/10-get_post_tags/app.py @@ -1,8 +1,15 @@ import requests def get_post_tags(post_id): - # your code here - return None + post_body = int + url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php" + resp = requests.get(url).json() + + for post in resp['posts']: + if (post["id"] == post_id): + return post + + print(get_post_tags(146)) \ No newline at end of file