Skip to content

Commit 349e6d4

Browse files
Merge pull request #90 from PdxCodeGuild/justin-lab08-api
finished both labs
2 parents 045c46a + 193c944 commit 349e6d4

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

code/justin/lab08_version1.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
Justin Young
3+
Lab 08
4+
Version1
5+
'''
6+
7+
import requests
8+
import time
9+
10+
response = requests.get("https://icanhazdadjoke.com", headers={'Accept': 'application/json'})
11+
call = response.json()
12+
x = input('wanna hear a joke? y/n: ')
13+
if x == 'y':
14+
print(call['joke'])
15+
16+

code/justin/lab08_version2.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
Justin Young
3+
Lab 08
4+
Version2
5+
'''
6+
7+
import requests
8+
import time
9+
10+
11+
u_input = input('enter a search term: ')
12+
response = requests.get(f"https://icanhazdadjoke.com/search?term=${u_input}", headers={
13+
'Accept': 'application/json'
14+
})
15+
16+
js = response.json()
17+
total = js['total_jokes']
18+
for j in js['results']:
19+
print(f'\nThere are {total} more jokes with the word {u_input}, get ready for the next one!!')
20+
total -= 1
21+
time.sleep(3)
22+
print('\n----------------------------------------------------------------------')
23+
print(j['joke'])
24+
print('----------------------------------------------------------------------')
25+
if total == 0:
26+
print(f'Thats all the jokes with {u_input}, thanks!')
27+
break
28+
a = input(f'\nLOL! Funny right? another joke? y/n: ')
29+
if a.lower() == 'n':
30+
break
31+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# import requests
2+
3+
# response = requests.get('https://google.com')
4+
# # print(response)
5+
# # print(type(response))
6+
# # print(response.text)
7+
# print(response.status_code)
8+
9+
# response = requests.get('https://api.chucknorris.io/jokes/random')
10+
11+
# print(response)
12+
# print(response.text)
13+
14+
# joke = response.text
15+
# joke = response.json() #python friendly dictionary0--------
16+
# # print(joke)
17+
# # print(joke['value'])
18+
19+
20+
# response = requests.get('https://api.chucknorris.io/jokes/categories')
21+
# # print(response.json())
22+
23+
# categories = response.json()
24+
25+
# # for category in categories:
26+
# # print(category)
27+
28+
# for i in range(len(categories)):
29+
# print(i, categories[i])
30+
31+
# choice = int(input('Select a category: '))
32+
33+
# query = {
34+
# 'category' : categories[choice]
35+
# }
36+
37+
# # response = requests.get(f'https://api.chucknorris.io/jokes/random?category={categories[choice]}')
38+
# response = requests.get('https://api.chucknorris.io/jokes/random', params=query)
39+
40+
# print(response.text)
41+
42+
import requests
43+
url = 'https://ghibliapi.herokuapp.com/films'
44+
response = requests.get(url)
45+
print(response)
46+
# print(response.text)
47+
print(response.json())
48+
data = response.json()
49+
# print(data[0]['title'])
50+
# for film in data:
51+
# print(film['title'])
52+
# print(film['release_date'])
53+
# print(film['description'])
54+
# print('-'*10)

0 commit comments

Comments
 (0)