Skip to content

Commit c86c76a

Browse files
A start of the Address Book Excercise
1 parent 6b24ad2 commit c86c76a

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

week-09/code/address_book/a_book.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"first_name": "Chris",
4+
"last_name": "Barker",
5+
"phone": "123-456-7890",
6+
"email": "[email protected]"
7+
},
8+
{
9+
"first_name": "Fred",
10+
"last_name": "Jones",
11+
"phone": "510-555-1234",
12+
"email": "FredJones@some_company.com"
13+
},
14+
{
15+
"first_name": "Nancy",
16+
"last_name": "Wilson",
17+
"phone": "423-321-9876",
18+
"email": "[email protected]"
19+
}
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[
2+
{
3+
"first_name": "Chris",
4+
"last_name": "Barker",
5+
"office_phone": "123-456-7890",
6+
"home_phone": "206-555-1234",
7+
"address": {
8+
"line_1": "835 NE 33rd St",
9+
"city": "Seattle",
10+
"state": "WA",
11+
"line_2": "",
12+
"zip": "96543"
13+
},
14+
"cell_phone": "234-567-8901",
15+
"email": "[email protected]"
16+
},
17+
{
18+
"first_name": "Fred",
19+
"last_name": "Jones",
20+
"office_phone": "564-466-7990",
21+
"home_phone": "510-555-1234",
22+
"address": {
23+
"line_1": "123 SE 13th St",
24+
"city": "Tacoma",
25+
"state": "WA",
26+
"line_2": "Apt. 43",
27+
"zip": "93465"
28+
},
29+
"cell_phone": "403-561-8911",
30+
"email": "FredJones@some_company.com"
31+
},
32+
{
33+
"first_name": "Nancy",
34+
"last_name": "Wilson",
35+
"office_phone": "123-765-9877",
36+
"home_phone": "423-321-9876",
37+
"address": {
38+
"line_1": "8654 Walnut St",
39+
"city": "Pasadena",
40+
"state": "CA",
41+
"line_2": "Suite 567",
42+
"zip": "12345"
43+
},
44+
"cell_phone": "432-567-8466",
45+
"email": "[email protected]"
46+
}
47+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
application logic code for ultra simple
5+
address book app...
6+
"""
7+
8+
import json
9+
10+
class AddressBook(object):
11+
"""
12+
very simple data model -- just a list of dicts
13+
"""
14+
def __init__(self):
15+
self.book = []
16+
17+
def save_to_file(self, filename='a_book.json'):
18+
json.dump(self.book, open(filename, 'wb'), indent=4 )
19+
20+
def load_from_file(self, filename='a_book.json'):
21+
self.book = json.load( open(filename, 'rb') )
22+
23+
24+
if __name__ == "__main__":
25+
import pprint
26+
a_book = AddressBook()
27+
a_book.load_from_file()
28+
29+
pprint.pprint(a_book.book)
30+

0 commit comments

Comments
 (0)