File tree Expand file tree Collapse file tree 7 files changed +57
-7
lines changed Expand file tree Collapse file tree 7 files changed +57
-7
lines changed Original file line number Diff line number Diff line change
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 ))
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ # Your code here
Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ response = requests .post ("https://assets.breatheco.de/apis/fake/sample/save-project-json.php" )
4
+ print (response .text )
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
def get_post_tags (post_id ):
4
- # Your code here
5
- return None
4
+ url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
5
+
6
+ response = requests .get (url )
7
+
8
+ if response .status_code == 200 :
9
+ data = response .json ()
10
+
11
+ for post in data ["posts" ]:
12
+ if post ["id" ] == post_id :
13
+ return post ["tags" ]
14
+ print ("No post found" )
15
+
16
+ else :
17
+ print ("Failed to fetch data from the endpoint." )
6
18
7
19
8
20
print (get_post_tags (146 ))
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
3
def get_attachment_by_id (attachment_id ):
4
- # Your code here
5
- return None
4
+ url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
5
+
6
+ response = requests .get (url )
7
+
8
+ if response .status_code == 200 :
9
+ data = response .json ()
10
+
11
+ for post in data ["posts" ]:
12
+ if "attachments" in post :
13
+ for attachment in post ['attachments' ]:
14
+ if attachment ['id' ] == attachment_id :
15
+ return attachment ['title' ]
16
+ print ("No attachment found" )
17
+
18
+ else :
19
+ print ("Failed to fetch data from the endpoint." )
6
20
7
21
print (get_attachment_by_id (137 ))
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- # Your code here
3
+ url = 'https://assets.breatheco.de/apis/fake/sample/post.php'
4
+ myobj = {'somekey' : 'somevalue' }
5
+
6
+ x = requests .post (url , json = myobj )
7
+
8
+ print (x .text )
Original file line number Diff line number Diff line change 1
1
import requests
2
2
3
- response = requests .post ("https://assets.breatheco.de/apis/fake/sample/save-project-json.php" )
4
- print (response .text )
3
+ url = 'https://assets.breatheco.de/apis/fake/sample/save-project-json.php'
4
+ myobj = {"id" : 2323 ,"title" : "Very big project" }
5
+ headers = {"Content-Type" : "application/json" }
6
+
7
+ x = requests .post (url , json = myobj , headers = headers )
8
+
9
+ print (x .text )
You can’t perform that action at this time.
0 commit comments