Skip to content

Commit 293a1a1

Browse files
solution
1 parent e1ac720 commit 293a1a1

File tree

20 files changed

+194
-12
lines changed

20 files changed

+194
-12
lines changed

.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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import requests
2+
3+
def get_titles():
4+
# Your code here
5+
return None
6+
7+
8+
print(get_titles())

.learn/resets/10-get-post-tags/app.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import requests
2+
3+
def get_post_tags(post_id):
4+
# Your code here
5+
return None
6+
7+
8+
print(get_post_tags(146))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import requests
2+
3+
def get_attachment_by_id(attachment_id):
4+
# Your code here
5+
return None
6+
7+
print(get_attachment_by_id(137))

.learn/resets/12-post-request/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,4 @@
1+
import requests
2+
3+
response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
4+
print(response.text)
+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
import requests
22

33
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
4+
5+
if response.status_code == 200:
6+
timeData = response.json()
7+
8+
hours = timeData["hours"]
9+
minutes = timeData["minutes"]
10+
seconds = timeData["seconds"]
11+
12+
print(f"Current time: { hours } hrs { minutes } min and { seconds } sec")
13+
else:
14+
print("Failed to fetch current time.")
15+

exercises/05-project-name/app.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
import requests
22

3-
# Your code here
3+
# Your code here
4+
5+
6+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project1.php")
7+
8+
if response.status_code == 200:
9+
Data = response.json()
10+
11+
name = Data["name"]
12+
13+
print(name)
14+
else:
15+
print("Failed to fetch current time.")
16+

exercises/06-project-list/app.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
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+
8+
if response.status_code == 200:
9+
Data = response.json()
10+
11+
second = Data[1]["name"]
12+
13+
print(second)
14+
else:
15+
print("Failed to fetch current time.")
16+
+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
import requests
22

3-
# Your code here
3+
# Your code here
4+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")
5+
6+
if response.status_code == 200:
7+
# Parsing JSON response
8+
project_list = response.json()
9+
10+
# Extracting the last project
11+
last_project = project_list[-1]
12+
13+
# Extracting the last image URL
14+
last_image_url = last_project["images"][-1]
15+
16+
# Printing the last image URL
17+
print(last_image_url)
18+
else:
19+
print("Failed to fetch project list.")

exercises/07-project-list-image/solution.hide.py

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

33
# Your code here
4-
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")
4+
response = requests.get("https://image.shutterstock.com/image-vector/trophy-cup-award-vector-icon-260nw-592525184.jpg")
55

66
if response.status_code == 200:
77
# Parsing JSON response

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

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

3-
# Your code here
3+
# Your code here
4+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
5+
6+
if response.status_code == 200:
7+
data = response.json()
8+
9+
first_post = data["posts"][0]
10+
11+
author_dict = first_post["author"]
12+
13+
author_name = author_dict["name"]
14+
15+
print(author_name)
16+
else:
17+
print("Failed to fetch data from the endpoint.")
+19-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import requests
22

33
def get_titles():
4-
# Your code here
5-
return None
4+
5+
6+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
7+
8+
titles = []
9+
10+
response = requests.get(url)
11+
12+
if response.status_code == 200:
13+
data = response.json()
14+
15+
for post in data["posts"]:
16+
title = post["title"]
17+
if title:
18+
titles.append(title)
19+
else:
20+
print("Error")
21+
22+
return titles
623

724

825
print(get_titles())

exercises/10-get-post-tags/app.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import requests
22

33
def get_post_tags(post_id):
4-
# Your code here
5-
return None
4+
5+
6+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
7+
8+
postTags = []
9+
10+
response = requests.get(url)
11+
12+
if response.status_code == 200:
13+
data = response.json()
14+
15+
for post in data["posts"]:
16+
if post["id"] == post_id:
17+
return post["tags"]
18+
else:
19+
print("Error")
20+
21+
return postTags
622

723

824
print(get_post_tags(146))
+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
import requests
22

33
def get_attachment_by_id(attachment_id):
4-
# Your code here
4+
5+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
6+
7+
postTags = []
8+
response = requests.get(url)
9+
if response.status_code == 200:
10+
11+
data = response.json()
12+
13+
for post in data["posts"]:
14+
15+
if "attachments" in post:
16+
17+
for attachment in post["attachments"]:
18+
if attachment["id"] == attachment_id:
19+
return attachment["title"]
20+
else:
21+
print("Error")
22+
23+
24+
25+
526
return None
627

728
print(get_attachment_by_id(137))

exercises/12-post-request/app.py

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

3-
# Your code here
3+
url = "https://assets.breatheco.de/apis/fake/sample/post.php"
4+
5+
response = requests.post(url)
6+
7+
print(response.text)

exercises/13-post-request-body/app.py

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

3-
response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
3+
url = "https://assets.breatheco.de/apis/fake/sample/save-project-json.php"
4+
5+
data = {
6+
"id": 2323,
7+
"title": "Very big project"
8+
}
9+
10+
# Setting the headers
11+
headers = {
12+
"Content-Type": "application/json"
13+
}
14+
15+
# Sending POST request with dictionary data
16+
response = requests.post(url, json=data, headers=headers)
17+
418
print(response.text)

0 commit comments

Comments
 (0)