Ejemplo n.º 1
0
    def __init__(self):
        super().__init__()
        self.agenda = 'agenda.bin'
        if not path.exists(self.agenda):
            while True:
                self.append(entrada())
                if go_on('contato') == 'N':
                    break
            with open(self.agenda, 'w+b') as agenda_criar:
                for contato in self:
                    agenda_criar.write(f'{contato.fullname():<40}: '
                                       f'{contato["fone"]:<15}: '
                                       f'{contato.aniver()} \n'.encode())
        else:
            with open(self.agenda, 'rb') as agenda_bin:
                for contato in agenda_bin:
                    contato = contato.decode().replace('\n', '').split(':')

                    contato = Contato(
                        nome=contato[0].strip().split()[0],
                        sobrenome=contato[0].strip().split()[1],
                        fone=int(contato[1].strip()),
                        aniver=[
                            int(x) for x in contato[2].strip().split('/')
                            if x.isnumeric()
                        ])
                    self.append(contato)
            self._menu()
            self._gravar()
Ejemplo n.º 2
0
 def __init__(self):
     super().__init__()
     self.pe = 'notas_entrada.txt'
     if path.exists(self.pe):
         with open(self.pe) as ne:
             for st in ne:
                 stu = st.replace('\n', '').split(':')
                 n = [float(a) for a in stu[1] if a.isnumeric()]
                 s = {'nome': stu[0].strip().title(), 'notas': n}
                 self.append(s)
     else:
         while True:
             self.append(Alunx())
             if go_on('alunx') == 'N':
                 break
Ejemplo n.º 3
0
 def usa(self):
     usados = []
     while True:
         print('- ' * 15)
         cod = int(input('Insira código do produto: ').strip())
         for p in self:
             if cod == p['codigo']:
                 n = int(
                     input(f'Quantidade de {p["nome"]} usadxs: ').strip())
                 p['qtd'] -= n
                 usados.append({'nome': p['nome'], 'qtd': p['qtd']})
         if go_on('uso') == 'N':
             break
     print('- ' * 15)
     for u in usados:
         print(f'{u["nome"]}: {u["qtd"]}')
Ejemplo n.º 4
0
 def compra(self):
     compras = []
     while True:
         print('- ' * 15)
         cod = int(input('Insira código do produto: ').strip())
         for p in self:
             if cod == p['codigo']:
                 n = int(
                     input(
                         f'Quantidade de {p["nome"]} compradxs: ').strip())
                 p['qtd'] += n
                 compras.append({'nome': p['nome'], 'qtd': p['qtd']})
         if go_on('compra') == 'N':
             break
     print('- ' * 15)
     for c in compras:
         print(f'{c["nome"]}: {c["qtd"]}')
Ejemplo n.º 5
0
 def __init__(self):
     super().__init__()
     if path.exists('despensa.bin'):
         with open('despensa.bin', 'rb') as d:
             for p in d:
                 pr = p.decode().replace('\n', '').split(':')
                 produto = {
                     'codigo': int(pr[0].strip()),
                     'nome': pr[1].strip().title(),
                     'qtd': int(pr[2].strip())
                 }
                 self.append(produto)
     else:
         while True:
             self.append(Produto())
             if go_on('produto') == 'N':
                 break
Ejemplo n.º 6
0
 def __init__(self):
     super().__init__()
     if os.path.exists('notas_alunx.txt'):
         with open('notas_alunx.txt') as ns:
             for alun in ns:
                 alunx = alun.replace('\n',
                                      '').replace('NOME:',
                                                  '').replace('NOTA:',
                                                              '').split('-')
                 al = {
                     'nome': alunx[0].strip(),
                     'nota': float(alunx[1].strip())
                 }
                 self.append(al)
     else:
         while True:
             print('- ' * 15)
             self.append(Alunx())
             if go_on('alunx') == 'N':
                 break
from csv import DictWriter
from validacao import go_on

with open('arquivo_teste.csv', 'a') as file:
    headers = ('Nome', 'Gênero', 'Diretor(a)')
    csv_writer = DictWriter(file, fieldnames=headers)
    csv_writer.writeheader()
    while True:
        nome = input('Nome: ').strip().title()
        genero = input('Gênero: ').strip().title()
        diretor = input('Diretor: ').strip().title()
        csv_writer.writerow({
            'Nome': nome,
            'Gênero': genero,
            'Diretor(a)': diretor
        })
        if go_on('filme') == 'N':
            break