Skip to content

Commit 44c6f29

Browse files
committed
Add exercises
1 parent fbb1723 commit 44c6f29

File tree

16 files changed

+81
-6
lines changed

16 files changed

+81
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import requests
2+
3+
url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
4+
# url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
5+
response = requests.get(url)
6+
7+
print("The response status is: "+str(response.status_code))

.learn/resets/02-random-status/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php")

.learn/resets/03-response-body/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
url = "https://assets.breatheco.de/apis/fake/sample/random-status.php"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import requests
2+
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
4+
print(response.text)

.learn/resets/05-project-name/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
# Your code here

.learn/resets/06-project-list/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
# Your code here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
# Your code here
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
3+
# Your code here

exercises/01-creating-a-request/app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import requests
22

3-
url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
3+
url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
44
# url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
55
response = requests.get(url)
66

exercises/02-random-status/app.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
import requests
22

33
response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php")
4+
5+
if response.status_code == 404:
6+
print("The URL you asked for is not found")
7+
8+
elif response.status_code == 503:
9+
print("Unavailable right now")
10+
11+
elif response.status_code == 200:
12+
print("Everything went perfect")
13+
14+
elif response.status_code == 400:
15+
print("Something is wrong with the request params")
16+
17+
else:
18+
print("Unknown status code")

exercises/03-response-body/app.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import requests
22

33
url = "https://assets.breatheco.de/apis/fake/sample/random-status.php"
4+
response = requests.get(url)
5+
6+
if response.status_code == 200:
7+
print(response.text)
8+
else:
9+
print("Something went wrong")
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import requests
22

33
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
4-
print(response.text)
4+
5+
response_body = response.json()
6+
print("Current time:", response_body["hours"] + " hrs " + response_body["minutes"] + " min and " + response_body["seconds"] + " sec")

exercises/05-project-name/app.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import requests
22

3-
# Your code here
3+
# Your code here
4+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project1.php")
5+
6+
response_body = response.json()
7+
8+
print(response_body["name"])

exercises/06-project-list/app.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import requests
22

3-
# Your code here
3+
# Your code here
4+
5+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")
6+
7+
response_body = response.json()
8+
9+
print(response_body[1]["name"])
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import requests
22

3-
# Your code here
3+
# Your code here
4+
5+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")
6+
7+
response_body = response.json()
8+
9+
print(response_body[2]["images"][2])

exercises/08-blog-post-author/app.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import requests
22

3-
# Your code here
3+
# Your code here
4+
5+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
6+
7+
response_body = response.json()
8+
9+
print(response_body)

0 commit comments

Comments
 (0)