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 a725da2

Browse files
WIP
1 parent 161de0f commit a725da2

File tree

3 files changed

+29
-4
lines changed
  • .learn/resets/11-get_attachment_by_id
  • exercises

3 files changed

+29
-4
lines changed
Lines changed: 7 additions & 0 deletions
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))

‎exercises/10-get_post_tags/app.py‎

Lines changed: 11 additions & 2 deletions
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-
returnNone
5+
tags= []
66

7+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
78

8-
print(get_post_tags(146))
9+
json_response = response.json()
10+
11+
post_by_id = [post for post in json_response['posts'] if post.get('id') == post_id]
12+
13+
return post_by_id[0]['tags']
14+
15+
16+
17+
print(get_post_tags(135))
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import requests
22

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

7-
print(get_attachment_by_id(137))
16+
print(get_attachment_by_id(138))

0 commit comments

Comments
(0)

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