Skip to content

Commit b376f6a

Browse files
First commit
1 parent f90a785 commit b376f6a

File tree

26 files changed

+166
-19
lines changed

26 files changed

+166
-19
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
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)

exercises/02-random-status/app.py

+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/random-status.php")
4+
5+
6+
if response.status_code == 404:
7+
print("The URL you asked for is not found")
8+
elif response.status_code == 503:
9+
print("Unavailable right now")
10+
elif response.status_code == 200:
11+
print("Everything went perfect")
12+
elif response.status_code == 400:
13+
print("Something is wrong with the request params")
14+
else:
15+
print("Unknown status code")

exercises/03-response-body/app.py

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

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

33
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
4-
print(response.text)
4+
5+
if response.status_code == 200:
6+
tiempo = response.json()
7+
horas = tiempo["hours"]
8+
minutos = tiempo["minutes"]
9+
segundos = tiempo["seconds"]
10+
print("Hora actual: ", horas,"h", minutos,"min", segundos, "seg")
11+
else:
12+
None

exercises/05-project-name/app.py

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

3-
# Your code here
3+
url = "https://assets.breatheco.de/apis/fake/sample/project1.php"
4+
5+
response = requests.get(url)
6+
7+
if response.status_code == 200:
8+
diccionario_propiedades_objeto =response.json()
9+
print(diccionario_propiedades_objeto["name"])
10+
else:
11+
print("Something went wrong")

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+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")
4+
5+
if response.status_code ==200:
6+
body = response.json()
7+
print(body[1]["name"])
8+
else:
9+
print("Something went wrong")
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import requests
22

3-
# Your code here
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/project_list.php")
4+
if response.status_code == 200 :
5+
body = response.json()
6+
print(body[2]["images"][2])
7+
else:
8+
print("Something went wrong")

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

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

3-
# Your code here
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
4+
5+
if response.status_code==200:
6+
body = response.json()
7+
print(body["posts"][0]["author"]["name"]) #objeto diccionario
8+
9+
#print(diccionario.keys())
10+

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

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

3-
def get_titles():
4-
# Your code here
5-
return None
63

4+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
5+
6+
7+
def get_titles():
8+
if response.status_code==200:
9+
body = response.json()
10+
return [n["title_plain"] for n in body["posts"]]
11+
else:
12+
None
13+
14+
print(get_titles())
715

8-
print(get_titles())

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

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

33
def get_post_tags(post_id):
4-
# Your code here
5-
return None
4+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
5+
if response.status_code==200:
6+
body = response.json()
7+
#print([n["id"] for n in body["posts"] ]) Id"s
8+
resultado = [n["tags"] for n in body["posts"] if n["id"] == post_id]
9+
return resultado[0]
10+
else:
11+
None
612

13+
print(get_post_tags(146))
714

8-
print(get_post_tags(146))
+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import requests
22

33
def get_attachment_by_id(attachment_id):
4-
# Your code here
5-
return None
4+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php")
5+
if response.status_code==200:
6+
body = response.json()
7+
resultado = [i['title'] for n in body['posts'] for i in n['attachments'] if i['id'] == attachment_id ]
8+
return resultado[0]
69

7-
print(get_attachment_by_id(137))
10+
print(get_attachment_by_id(137))

exercises/11-get-attachment-by-id/solution.hide.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def get_attachment_by_id(attachment_id):
2222
else:
2323
print("Failed to fetch data from the endpoint.")
2424

25-
print(get_attachment_by_id(137))
25+
print(get_attachment_by_id(138))

exercises/12-post-request/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+
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)

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)