Skip to content

Commit afcfe4f

Browse files
committed
avance
1 parent 8b6eb7b commit afcfe4f

File tree

22 files changed

+117
-15
lines changed

22 files changed

+117
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import requests
2+
3+
url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
4+
response = requests.get(url)
5+
6+
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"

.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))

.vscode/settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"editor.minimap.enabled": false,
55
"workbench.editorAssociations": {
66
"*.md": "vscode.markdown.preview.editor"
7-
}
7+
},
8+
"python.analysis.autoImportCompletions": true,
9+
"python.analysis.typeCheckingMode": "basic"
810
}

exercises/01-what-is-a-request/app.py

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

3-
url = "https://assets.breatheco.de/apis/fake/sample/404-example.php"
3+
url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
44
response = requests.get(url)
55

6-
print("The response status is: "+str(response.status_code))
6+
print(f"The response status is: {response.status_code}") #El test está mal

exercises/01-what-is-a-request/test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
def test_url(app):
66
with patch('requests.get') as mock_request:
77
app()
8-
url = "https://assets.breatheco.de/apis/fake/sample/hello.php"
8+
url = "https://assets.breatheco.de/apis/fake/sample/hello.php
9+
"
910
assert mock_request.call_args.args[0] == url

exercises/02-random-status/app.py

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

33
response = requests.get("https://assets.breatheco.de/apis/fake/sample/random-status.php")
4+
5+
def error_code (status):
6+
if (status == 200):
7+
return "Everything went perfect\n"
8+
elif (status == 400):
9+
return "Something is wrong on the request params\n"
10+
elif (status == 404):
11+
return "The URL you asked is not found\n"
12+
elif (status == 503):
13+
return "Unavailable right now\n"
14+
15+
# TEST FALLAN AUNQUE LAS RESPUETAS SEAN LA CORRECTAS: SyntaxError: invalid decimal literal
16+
17+
print(error_code(response.status_code))

exercises/03-response-body/app.py

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

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

3-
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php")
4-
print(response.text)
3+
response = requests.get("https://assets.breatheco.de/apis/fake/sample/time.php").json()
4+
5+
print(f"Current time: {response['hours']} hrs {response['minutes']} and {response['seconds']} sec")

exercises/05-project-name/app.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from urllib import request, response
12
import requests
23

3-
# your code here
4+
# your code here
5+
url = "https://assets.breatheco.de/apis/fake/sample/project1.php"
6+
resp = requests.get(url).json()
7+
8+
print(resp['name'])

exercises/06-project-list/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+
# your code here
4+
url = "https://assets.breatheco.de/apis/fake/sample/project_list.php"
5+
resp = requests.get(url).json()
6+
7+
print(resp[1]['name'])
+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
import requests
22

3-
# your code here
3+
# your code here
4+
url = "https://assets.breatheco.de/apis/fake/sample/project_list.php"
5+
resp = requests.get(url).json()
6+
7+
print(resp[-1]['images'][-1])

exercises/08-blog-post-author/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+
# your code here
4+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
5+
resp = requests.get(url).json()
6+
7+
print(resp['posts'][1]['author']['name'])
+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import requests
22

3+
34
def get_titles():
4-
# your code here
5-
return None
5+
arr_titles = []
6+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
7+
resp = requests.get(url).json()
8+
9+
for post in resp['posts']:
10+
arr_titles.append(post['title'])\
11+
12+
return arr_titles
613

714

815
print(get_titles())

exercises/10-get_post_tags/app.py

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

33
def get_post_tags(post_id):
4-
# your code here
5-
return None
4+
post_body = int
5+
url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
6+
resp = requests.get(url).json()
7+
8+
for post in resp['posts']:
9+
if (post["id"] == post_id):
10+
return post
11+
12+
613

714

815
print(get_post_tags(146))

0 commit comments

Comments
 (0)