Skip to content

Commit 0109b70

Browse files
committed
initial commit
1 parent eddb884 commit 0109b70

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

code/kaceyb/python/lab09/lab_09.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# VERSION 1 #
2+
3+
4+
import json
5+
import requests
6+
7+
# response = requests.get("https://favqs.com/api/qotd")
8+
9+
#
10+
# print(response)
11+
# print(type(response))
12+
# print(response.text)
13+
# print(response.status_code)
14+
15+
# quote = response.text
16+
# json_response = response.json()
17+
18+
# quote_author = json_response['quote']['author']
19+
20+
# quote_body = json_response['quote']['body']
21+
22+
# print(f'The author is {quote_author}\nTheir quote: {quote_body}')
23+
24+
25+
26+
27+
# VERSION 2 #
28+
29+
30+
31+
import pprint
32+
33+
34+
35+
36+
37+
page_number = 1
38+
39+
search_term = 'everything'
40+
41+
42+
response = requests.get(f"https://favqs.com/api/quotes?page={page_number}&filter={search_term}",
43+
headers = {'Authorization': 'Token token="855df50978dc9afd6bf86579913c9f8b"'},)
44+
45+
46+
json_response = response.json()
47+
# pprint.pprint(json_response)
48+
is_last_page = json_response['last_page']
49+
50+
51+
# is_last_page ==
52+
# pprint.pprint(json_response['quotes'])
53+
# pprint.pprint(json_response['quotes'][0])
54+
55+
quotes_list = []
56+
57+
for i in range(len(json_response['quotes'])):
58+
59+
author_json = json_response['quotes'][i]['author']
60+
quote_json = json_response['quotes'][i]['body']
61+
62+
quote_dictionary = {
63+
'author': author_json,
64+
'quote': quote_json
65+
}
66+
quotes_list.append(quote_dictionary)
67+
pprint.pprint(quotes_list)
68+
# print(len(json_response['quotes']))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# with open('location.csv', 'w') as file:
2+
# file.write("Hello World")
3+
4+
# # with open(file, 'r') as f:
5+
# # contents = f.readlines()
6+
# # print(contents)
7+
8+
# with open(file, 'r') as f:
9+
# for line in f:
10+
# list.append(line)
11+
12+
# phonebook = {'Dave': '42342', 'Alice': '234234'}
13+
# with open(file, 'w') as location:
14+
# for name, number in location.items():
15+
# line = f'{name}{number}\n'
16+
# location.write(line)
17+
18+
19+
20+
#CSV = comma separated values
21+
22+
# with open('contacts.csv', 'w') as file:
23+
# lines = file.read().split('\n')
24+
# print(lines)
25+
26+
contacts = [
27+
{'name':'matthew', 'favorite fruit':'blackberries', 'favorite color':'orange'},
28+
{'name':'sam', 'favorite fruit':'pineapple', 'favorite color':'purple'},
29+
{'name': 'teeto', 'favorite fruit':'lychee', 'favorite color':'brown'}
30+
]
31+
32+
f = open('contacts.csv')
33+
34+
with open('contacts.csv', 'r') as contacts:
35+
contacts_data = contacts.read().split('\n')
36+
37+
dict = []
38+
for line in contacts_data:
39+
dict.append(contacts_data)
40+

code/kaceyb/python/notes/lesson06/contacts.csv

Whitespace-only changes.

code/kaceyb/python/notes/lesson06/lesson_11.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World

0 commit comments

Comments
 (0)