Manejo de personas
This commit is contained in:
40
src/address_book.py
Normal file
40
src/address_book.py
Normal file
@ -0,0 +1,40 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
class Contact:
|
||||
def __init__(self):
|
||||
self.names = ''
|
||||
self.last_name = ''
|
||||
self.maiden_name = ''
|
||||
self.emails = []
|
||||
self.phones = []
|
||||
|
||||
def full_name(self):
|
||||
return ' '.join([self.names, self.last_name, self.maiden_name])
|
||||
|
||||
|
||||
class AddressBook:
|
||||
def __init__(self, data_folder):
|
||||
filename = os.path.join(data_folder, 'address_book.json')
|
||||
with open(filename, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
self.contacts = []
|
||||
for c in data:
|
||||
contact = Contact()
|
||||
for k, val in c.items():
|
||||
setattr(contact, k, val)
|
||||
self.contacts.append(contact)
|
||||
|
||||
def find(self, name):
|
||||
for c in self.contacts:
|
||||
if c.full_name() == name or c.names == name or c.last_name == name:
|
||||
return c
|
||||
return None
|
||||
|
||||
def find_id(self, name):
|
||||
for (k, c) in enumerate(self.contacts):
|
||||
if c.full_name() == name or c.names == name or c.last_name == name:
|
||||
return k
|
||||
return -1
|
Reference in New Issue
Block a user