-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclients.py
83 lines (66 loc) · 2.37 KB
/
clients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Create clients
"""
"""
TO DO:
include email history for clients
"""
import csv
# clients go here from create client from list func
clients_list = []
class Client:
""" client class, create clients."""
def __init__(self, first, last, job, company, email, replies=0, searches=0):
self.first = first
self.last = last
self.job = job
self.company = company
self.email = email
self.replies = replies
self.searches = searches
def __str__(self):
""" Returns client object as client detail """
return f"Name: {self.first} {self.last} Job: {self.job} Company: {self.company} email: {self.email}"
def __repr__(self):
""" Returns class object details"""
return f"Name: {self.first} {self.last} Job: {self.job} Company: {self.company} email: {self.email}"
def open_client_file_to_dict():
""" Opens csv of clients, converts to dictionary by specified csv fields. """
clients_dict = []
file = open(r'../clientmailerproj/client.csv', encoding='utf-8-sig')
client_ordered_dict = csv.DictReader(file)
for row in client_ordered_dict:
clients_dict.append({
'First': row['First Name'],
'Last': row['Last Name'],
'Company': row['Account Name'],
'Email': row['Email'],
'Job': row['Job']
})
return clients_dict
def create_client_from_dict():
""" Creates Client class from the dictionary of clients"""
for row in open_client_file_to_dict():
clients_list.append(Client(row['First'], row['Last'], row['Job'], row['Company'], row['Email']))
return
def search_for_clients(client_list, search_term):
""" Search for clients from client_list"""
matched_clients = []
for client in client_list:
if client.first == search_term or client.last == search_term or \
client.job == search_term or client.company == search_term:
matched_clients.append(client)
return matched_clients
def print_clients(client_list):
""" Print clients in client_list"""
if len(client_list) == 0:
print("Please try again, your list has no clients.")
return
else:
for client in client_list:
print(client)
return
# open_client_file_to_dict()
# create_client_from_dict()
# print(search_for_clients(clients_list, r'BBC'))
# print(clients_list)