Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 02ce065

Browse files
Add latest exercises
1 parent 44c6f29 commit 02ce065

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import requests
22

33
# Your code here
4-
54
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
65

76
response_body = response.json()
87

9-
print(response_body)
8+
print(response_body["posts"][0]["author"]["name"])

‎exercises/09-list-of-blog-titles/app.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import requests
22

33
def get_titles():
4+
titles = []
45
# Your code here
5-
return None
6+
7+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
8+
response_body = response.json()
9+
10+
# print(response_body)
11+
12+
for index, post in enumerate(response_body["posts"]):
13+
titles.append(post["title"])
14+
15+
return titles
616

717

818
print(get_titles())

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22

33
def get_post_tags(post_id):
44
# Your code here
5-
return None
5+
tags = []
6+
7+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
8+
response_body = response.json()
9+
10+
for post in response_body["posts"]:
11+
if post_id == post["id"]:
12+
tags = post["tags"]
13+
14+
return tags
615

716

817
print(get_post_tags(146))

‎exercises/11-get-attachment-by-id/app.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
def get_attachment_by_id(attachment_id):
44
# Your code here
5-
return None
5+
titles = " "
6+
7+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
8+
response_body = response.json()
9+
10+
for post in response_body["posts"]:
11+
for attachment in post["attachments"]:
12+
if attachment_id == attachment["id"]:
13+
14+
return attachment["title"]
615

716
print(get_attachment_by_id(137))

‎exercises/12-post-request/app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
import requests
22

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

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import requests
22

3-
response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
3+
data = {
4+
"id":2323,
5+
"title":"Very big project"
6+
}
7+
8+
headers = {
9+
'Content-Type':'application/json'
10+
}
11+
12+
response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php", headers=headers, json=data)
13+
414
print(response.text)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /