Implementacion mas completa de email y api para ingresar datos

This commit is contained in:
2020-11-16 23:33:49 -03:00
parent 1b57d705bb
commit 2d157f6989
14 changed files with 369 additions and 112 deletions

View File

@ -12,8 +12,8 @@ class Boss:
class Bosses:
def __init__(self, data_folder):
filename = os.path.join(data_folder, 'bosses.json')
with open(filename, 'r') as f:
self.filename = os.path.join(data_folder, 'bosses.json')
with open(self.filename, 'r') as f:
data = json.load(f)
self.bosses = []
addrs = AddressBook(data_folder)
@ -35,3 +35,29 @@ class Bosses:
if a in name:
return True
return False
def add_boss(self, name, aliases: list = None):
if self.is_boss(name):
return
b = Boss()
b.full_name = name
if aliases is not None:
b.aliases = aliases
def get(self, name):
if not self.is_boss(name):
return None
for i, boss in enumerate(self.bosses):
if boss.full_name in name:
return i
for m in boss.contact.emails:
if m in name:
return i
for a in boss.aliases:
if a in name:
return i
def save(self):
data = [{'full_name': boss.full_name, 'aliases': boss.aliases} for boss in self.bosses]
with open(self.filename, 'w') as f:
json.dump(data, f, indent=4)