diff --git a/bc.json b/bc.json index 6777bce..d4bbd8c 100644 --- a/bc.json +++ b/bc.json @@ -1,4 +1,184 @@ { + "port": 3000, + "address": "https://copper-louse-ibwq8nym.ws-us03.gitpod.io", + "editor": "gitpod", + "configPath": { + "config": "bc.json", + "base": ".learn", + "exercises": "./exercises", + "output": ".learn/dist" + }, + "outputPath": "./.learn/dist", + "publicPath": "/preview", + "grading": "isolated", + "ignoreRegex": null, + "webpack_template": null, + "disable_grading": false, + "onCompilerSuccess": null, "language": "python3", - "repository": "https://github.com/4GeeksAcademy/python-http-requests-api-tutorial-exercises" + "compiler": "python3", + "tester": "pytest", + "actions": [ + "run", + "test", + "reset" + ], + "repository": "https://github.com/4GeeksAcademy/python-http-requests-api-tutorial-exercises", + "session": 4159901724455659000, + "exercises": [ + { + "slug": "01-hello-world", + "title": "01-hello-world", + "done": false, + "path": "exercises/01-hello-world", + "translations": [ + "es", + "us" + ], + "graded": false + }, + { + "slug": "01-what-is-a-request", + "title": "01-what-is-a-request", + "done": true, + "path": "exercises/01-what-is-a-request", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "02-random-status", + "title": "02-random-status", + "done": true, + "path": "exercises/02-random-status", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "03-response-body", + "title": "03-response-body", + "done": true, + "path": "exercises/03-response-body", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "04-response-body-json", + "title": "04-response-body-json", + "done": true, + "path": "exercises/04-response-body-json", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "05-project-name", + "title": "05-project-name", + "done": true, + "path": "exercises/05-project-name", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "06-project-list", + "title": "06-project-list", + "done": true, + "path": "exercises/06-project-list", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "07-project-list-image", + "title": "07-project-list-image", + "done": true, + "path": "exercises/07-project-list-image", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "08-blog-post-author", + "title": "08-blog-post-author", + "done": false, + "path": "exercises/08-blog-post-author", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "09-array-of-blog-titles", + "title": "09-array-of-blog-titles", + "done": false, + "path": "exercises/09-array-of-blog-titles", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "10-get_post_tags", + "title": "10-get_post_tags", + "done": false, + "path": "exercises/10-get_post_tags", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "11-get_attachment_by_id", + "title": "11-get_attachment_by_id", + "done": false, + "path": "exercises/11-get_attachment_by_id", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "12-post-request", + "title": "12-post-request", + "done": false, + "path": "exercises/12-post-request", + "translations": [ + "es", + "us" + ], + "graded": true + }, + { + "slug": "13-post-request-body", + "title": "13-post-request-body", + "done": false, + "path": "exercises/13-post-request-body", + "translations": [ + "es", + "us" + ], + "graded": true + } + ] } \ 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..4834ba5 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 diff --git a/exercises/02-random-status/app.py b/exercises/02-random-status/app.py index d9ef815..b637afb 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 == 200: + print("Everything went perfect") +elif response.status_code == 400: + print("Something is wrong on the request params") +elif response.status_code == 404: + print("The URL you asked is not found") +elif response.status_code == 503: + print("Unavailable right now") +else: + print("anything") diff --git a/exercises/03-response-body/app.py b/exercises/03-response-body/app.py index 37cdac0..5b9b504 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" \ No newline at end of file +url = "https://assets.breatheco.de/apis/fake/sample/random-status.php" + +reponse= requests.get(url) + +if reponse.status_code == 200: + print(reponse.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..dc75a3e 100644 --- a/exercises/04-response-body-json/app.py +++ b/exercises/04-response-body-json/app.py @@ -1,4 +1,7 @@ import requests - +import json +time = {} response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php") -print(response.text) \ No newline at end of file + +time = response.json() +print(f"Current time: {time['hours']} hrs {time['minutes']} min and {time['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..b2ca899 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") + +course = response.json() +print(course['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..3d7503a 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 +response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php") + +project = response.json() + +print(project[1]['name']) diff --git a/exercises/07-project-list-image/app.py b/exercises/07-project-list-image/app.py index a471294..7c29cf6 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') + +project = response.json() + +print(project[-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..87125ab 100644 --- a/exercises/08-blog-post-author/app.py +++ b/exercises/08-blog-post-author/app.py @@ -1,3 +1,3 @@ import requests -# your code here \ No newline at end of file +# your code here