Sem resumo de edição
Sem resumo de edição
Linha 1: Linha 1:
<syntaxhighlight lang="py">
<syntaxhighlight lang="py">
19/06/2017 - 15:16
from tkinter import *
from functools import partial
#---------------------- JANELA *
janela = Tk()
janela.geometry("300x300+200+200")
janela.title("Think About Eat!")
#janela["bg"] = "#d1fce"
#--------------------------- fazer login *
def tenho_rest():
home.destroy()
login = Frame()
usuario = Label(login, text = "Usuário: ")
us = Entry()
us.pack()
senha = Label(login, text = "Senha: ")
se = Entry(show = '*')
se.pack()
def valido():
user = us.get()
password = se.get()
arquivo = open('senhas.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
for linha in texto:
lista = linha.split()
if lista[0] == user:
if lista[1] == password:
login.destroy()
us.destroy()
se.destroy()
meu_rest(lista[2])
else:
errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1")
errou.pack()
else:
errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1")
errou.pack()
finish = Button(login, text = "Pronto!", bg = "white", relief = "flat", command = valido)
finish.pack()
login.pack()
#---------------------- Tenho Restaurante *
def meu_rest(nome_rest):
rest = Frame()
rest["bg"] = "#d1fce1"
nome = Label(rest, text = nome_rest, bg = "#d1fce1")
nome.pack()
listbox = Listbox(rest, selectmode=EXTENDED)
listbox.pack()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
g = -1
for linha in texto:
lista = linha.split()
if lista[0] == nome_rest:
g+=1
if g != -1:
g+=1
if g == 2:
listbox.insert(END, "ENTRADAS")
listbox.insert(END, '')
i = 0
lista = linha.split()
while i < len(lista):
listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2])
i+=2
elif g == 3:
listbox.insert(END, '')
listbox.insert(END, "PRATOS PRINCIPAIS")
listbox.insert(END, '')
i = 0
lista = linha.split()
while i < len(lista):
listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2])
i+=2
elif g == 4:
listbox.insert(END, '')
listbox.insert(END, "SOBREMESAS")
listbox.insert(END, '')
i = 0
lista = linha.split()
while i < len(lista):
listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2])
i+=2
elif g == 5:
listbox.insert(END, '')
listbox.insert(END, "BEBIDAS")
listbox.insert(END, '')
i = 0
lista = linha.split()
while i < len(lista):
listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2])
i+=2
g = -1
break
# Função para adicionar algo no cardápio
def add_card():
add = Tk()
add.geometry("250x250+300+150")
add.title("Adicionar cardápio")
nome = nome_rest
t = Entry(add)
n = Entry(add)
p = Entry(add)
t.pack()
n.pack()
p.pack()
# Adiciona
def valide():
tipo = t.get()
novo = n.get()
preco = p.get()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
arquivo = open('dados.txt', 'w')
h = 0
g = -1
for linha in texto:
lista = linha.split()
if lista[0] == nome:
g = 0
if tipo == 'entrada':
h = 1
elif tipo == 'principal':
h = 2
elif tipo == 'sobremesa':
h = 3
else:
h = 4
if g != -1:
g+=1
if g == h:
k = len(linha)
linha += novo
linha += ' '
linha += preco
linha += ' '
arquivo.writelines(linha)
arquivo.close()
add.destroy()
rest.destroy()
meu_rest(nome_rest)
finish = Button(add, text = "Pronto!", bg = "white", relief = "flat", command = valide)
finish.place(x = 100, y = 300)
finish.pack()
add.mainloop()
b_add = Button(rest, compound = "left", bg = "white", text = "Adicionar cardápio", font = "Calibri 11", relief = "flat", command = add_card)
b_add.pack()
b_del = Button(rest, compound = "left", bg = "white", text = "Deletar cardápio", font = "Calibri 11", relief = "flat", command=del_card)
b_del.pack()
rest.pack()
#------------------- home
home = Frame(janela)
#home["bg"] = "#d1fce1"
tenho = Button(home, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat", command = tenho_rest)
tenho.pack()
home.pack()
janela.mainloop()
#*********************************************************************************************************************************************************************************


17/06/2017 - 22:42
17/06/2017 - 22:42
Linha 5: Linha 175:
from tkinter import *
from tkinter import *


#--------------------------------------- Deleta o restaurante
def delete_rest():
def delete_rest():
nome = input()
nome = input()
Linha 23: Linha 194:
k = -1
k = -1
arquivo.close()
arquivo.close()
 
#--------------------------------------- Adicionar algo ao cardápio
def add_card():
def add_card():
nome = input()
nome = input()
Linha 57: Linha 229:
arquivo.writelines(linha)
arquivo.writelines(linha)
arquivo.close()
arquivo.close()
 
#--------------------------------------- Deleta algo do cardápio
def del_card():
def del_card():
rest = input()
rest = input()
Linha 104: Linha 277:
    
    
    
    
 
#--------------------------------------------- Le as informações pra criar o restaurante
def read():
def read():
lista = []
lista = []
Linha 117: Linha 290:
return lista
return lista


 
#----------------------------------------------- Criar restaurante
def criar_rest():
def criar_rest():
restaurante = read()
restaurante = read()
Linha 148: Linha 321:
arquivo.close()
arquivo.close()


#---------------------- Procurar Restaurante
def procurar_rest():
def procurar_rest():
nome = input()
nome = input()
Linha 173: Linha 347:
#delete_rest()
#delete_rest()


#********************************************************************************
class restaurante():
class restaurante():
def __init__(self):
def __init__(self):
Linha 328: Linha 503:




*************************************************************************************************************************************************
#*************************************************************************************************************************************************




Linha 335: Linha 510:


% 16/06/2017 00:49  
% 16/06/2017 00:49  
#----------------------------- Deleta o restaurante
def delete_rest():
def delete_rest():
nome = input()
nome = input()
Linha 353: Linha 530:
k = -1
k = -1
arquivo.close()
arquivo.close()
#------------------------------------ Adiciona algo ao cardápio
def add_card():
def add_card():
nome = input()
nome = input()
Linha 388: Linha 565:
arquivo.close()
arquivo.close()
   
   
#---------------------- Deleta algo do cardápio
def del_card():
def del_card():
rest = input()
rest = input()
Linha 434: Linha 612:
    
    
    
    
 
#------------------------ Le as informações para criar o restaurante
def read():
def read():
lista = []
lista = []
Linha 447: Linha 625:
return lista
return lista


 
#--------------------------- Criar Restaurante
def criar_rest():
def criar_rest():
restaurante = read()
restaurante = read()
Linha 477: Linha 655:
arquivo.writelines(be)
arquivo.writelines(be)
arquivo.close()
arquivo.close()
 
#------------------- Procurar Restaurante
def procurar_rest():
def procurar_rest():
nome = input()
nome = input()
Linha 502: Linha 680:
print("Delete rest: ")
print("Delete rest: ")
delete_rest()
delete_rest()
#  16/06/2017 17:14
def delete_rest()
nome = input()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
arquivo = open('dados.txt', 'w')
k = -1;
for linha in texto
lista = linha.split()
if lista[0] == nome
k = 0
if k != -1
k+=1
if k == -1
arquivo.writelines(linha)
if k == 4
k = -1
arquivo.close()
def att_inf_rest()
rest = input()
inf = input()
nova = input()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
arquivo = open('dados.txt', 'w')
h = -1
while linha < len(texto)
lista = linha.append()
if lista[0] == rest
if inf == cnpj
h = 1
elif inf == endereco
h = 2
els
linha += 5
def add_card()
nome = input()
tipo = input()
novo = input()
preco = input()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
arquivo = open('dados.txt', 'w')
h = 0
g = -1
for linha in texto
lista = linha.split()
if lista[0] == nome
g = 0
if tipo == 'entrada'
h = 1
elif tipo == 'principal'
h = 2
elif tipo == 'sobremesa'
h = 3
else
h = 4
if g != -1
g++
if g == h
k = len(linha)
linha[k-1] = ' '
linha += novo
linha += ' '
linha += preco
arquivo.writelines(linha)
arquivo.close()
def del_card()
rest = input()
tipo = input()
comida = input()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
arquivo.close()
h = 0
g = -1
for linha in texto
lista = linha.split()
if lista[0] == nome
g = 0
if tipo == 'entrada'
h = 1
elif tipo == 'principal'
h = 2
elif tipo == 'sobremesa'
h = 3
else
h = 4
v = 0;
if g != -1
g++
if g == h
for i in linha
if i == comida
i = ''
v = 1
if v == 1
i = ''
break
arquivo.writelines(linha)
arquivo.close()
def read()
lista = []
nome = input()
lista.append(nome+'')
cnpj = input()
lista.append(cnpj+'')
endereco = input()
lista.append(endereco+'')
telefone = input()
lista.append(telefone+'\n')
return lista
def criar_rest()
restaurante = read()
arquivo = open('dados.txt', 'a')
arquivo.writelines(restaurante)
entrada = input()
precoe = input()
principal = input()
precop = input()
sobremesa = input()
precos = input()
bebida = input()
precob = input()
en = []
en.append(entrada+'')
en.append(precoe+'\n')
pri = []
pri.append(principal+'')
pri.append(precop+'\n')
sob = []
sob.append(sobremesa+'')
sob.append(precos+'\n')
be = []
be.append(bebida+'')
be.append(precob+'\n')
arquivo.writelines(en)
arquivo.writelines(pri)
arquivo.writelines(sob)
arquivo.writelines(be)
arquivo.close()
def procurar_rest()
nome = input()
arquivo = open('dados.txt', 'r')
texto = arquivo.readlines()
j = 0
while i < len(texto):
lista = i.split()
if lista[0] == nome
print(lista)
j = 1
break
i+=5
if j == 0
print('Restaurante nao encontrado')
arquivo.close()


</syntaxhighlight>
</syntaxhighlight>

Edição das 18h17min de 19 de junho de 2017

<syntaxhighlight lang="py">

19/06/2017 - 15:16

from tkinter import * from functools import partial

  1. ---------------------- JANELA *

janela = Tk() janela.geometry("300x300+200+200") janela.title("Think About Eat!")

  1. janela["bg"] = "#d1fce"
  1. --------------------------- fazer login *

def tenho_rest(): home.destroy() login = Frame() usuario = Label(login, text = "Usuário: ") us = Entry() us.pack() senha = Label(login, text = "Senha: ") se = Entry(show = '*') se.pack() def valido(): user = us.get() password = se.get() arquivo = open('senhas.txt', 'r') texto = arquivo.readlines() arquivo.close() for linha in texto: lista = linha.split() if lista[0] == user: if lista[1] == password: login.destroy() us.destroy() se.destroy() meu_rest(lista[2]) else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack() else: errou = Label(login, text = "Ahh, não! Algo está errado!", bg = "#d1fce1") errou.pack() finish = Button(login, text = "Pronto!", bg = "white", relief = "flat", command = valido) finish.pack() login.pack()

  1. ---------------------- Tenho Restaurante *

def meu_rest(nome_rest): rest = Frame() rest["bg"] = "#d1fce1" nome = Label(rest, text = nome_rest, bg = "#d1fce1") nome.pack() listbox = Listbox(rest, selectmode=EXTENDED) listbox.pack() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() g = -1 for linha in texto: lista = linha.split() if lista[0] == nome_rest: g+=1 if g != -1: g+=1 if g == 2: listbox.insert(END, "ENTRADAS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 elif g == 3: listbox.insert(END, ) listbox.insert(END, "PRATOS PRINCIPAIS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 elif g == 4: listbox.insert(END, ) listbox.insert(END, "SOBREMESAS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 elif g == 5: listbox.insert(END, ) listbox.insert(END, "BEBIDAS") listbox.insert(END, ) i = 0 lista = linha.split() while i < len(lista): listbox.insert(END, lista[i]+" "+lista[i+1])#*lista[i:i+2]) i+=2 g = -1 break # Função para adicionar algo no cardápio def add_card(): add = Tk() add.geometry("250x250+300+150") add.title("Adicionar cardápio") nome = nome_rest t = Entry(add) n = Entry(add) p = Entry(add) t.pack() n.pack() p.pack() # Adiciona def valide(): tipo = t.get() novo = n.get() preco = p.get() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -1 for linha in texto: lista = linha.split() if lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 if g != -1: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close() add.destroy() rest.destroy() meu_rest(nome_rest) finish = Button(add, text = "Pronto!", bg = "white", relief = "flat", command = valide) finish.place(x = 100, y = 300) finish.pack() add.mainloop()

b_add = Button(rest, compound = "left", bg = "white", text = "Adicionar cardápio", font = "Calibri 11", relief = "flat", command = add_card) b_add.pack() b_del = Button(rest, compound = "left", bg = "white", text = "Deletar cardápio", font = "Calibri 11", relief = "flat", command=del_card) b_del.pack() rest.pack()

  1. ------------------- home

home = Frame(janela)

  1. home["bg"] = "#d1fce1"

tenho = Button(home, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat", command = tenho_rest) tenho.pack() home.pack() janela.mainloop()


17/06/2017 - 22:42

from tkinter import *

  1. --------------------------------------- Deleta o restaurante

def delete_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') k = -2; for linha in texto: lista = linha.split() if lista[0] == nome: k = -1 if k != -2: k+=1 if k == -1: arquivo.writelines(linha) if k == 4: k = -1 arquivo.close()

  1. --------------------------------------- Adicionar algo ao cardápio

def add_card(): nome = input() tipo = input() novo = input() preco = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -1 for linha in texto: lista = linha.split() if lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 if g != -1: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close()

  1. --------------------------------------- Deleta algo do cardápio

def del_card(): rest = input() tipo = input() comida = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -2 for linha in texto: lista = linha.split() if lista[0] == rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 v = 0 u = 0 lista2 = [] if g != -2: g+=1 if g == h: s = u = 1 lista1 = linha.split() for i in lista1: if i == comida: v = 1 elif v == 1: v = 0 else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha) arquivo.close()


  1. --------------------------------------------- Le as informações pra criar o restaurante

def read(): lista = [] nome = input() lista.append(nome+' ') cnpj = input() lista.append(cnpj+' ') endereco = input() lista.append(endereco+' ') telefone = input() lista.append(telefone+'\n') return lista

  1. ----------------------------------------------- Criar restaurante

def criar_rest(): restaurante = read() arquivo = open('dados.txt', 'a') arquivo.writelines(restaurante) entrada = input() precoe = input() principal = input() precop = input() sobremesa = input() precos = input() bebida = input() precob = input() en = [] en.append(entrada+' ') en.append(precoe+'\n') pri = [] pri.append(principal+' ') pri.append(precop+'\n') sob = [] sob.append(sobremesa+' ') sob.append(precos+'\n') be = [] be.append(bebida+' ') be.append(precob+'\n') arquivo.writelines(en) arquivo.writelines(pri) arquivo.writelines(sob) arquivo.writelines(be) arquivo.close()

  1. ---------------------- Procurar Restaurante

def procurar_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() j = 0 for i in texto: lista = i.split() if lista[0] == nome: print(lista) j = 1 break if j == 0: print('Restaurante nao encontrado') arquivo.close()

  1. criar_rest()
  2. print("Procure: ")
  3. procurar_rest()
  4. print("Adicione cardapio: ")
  5. add_card()
  6. print("Delete cardapio: ")
  7. del_card()
  8. print("Delete rest: ")
  9. delete_rest()

class restaurante(): def __init__(self): nome = "-" cnpj = "-" telefone = "-" endereco = "-"

  1. ---------------------- JANELA *

janela = Tk() janela.geometry("500x500+200+200") janela.title("Think About Eat!") janela["bg"] = "#eeddff"

  1. --------------------------- fazer login *

login = Frame(janela) usuario = Label(login, text = "Usuário: ") us = Entry() senha = Label(login, text = "Senha: ") se = Entry(show = '*') user = us.get() password = se.get()


  1. -------------------------- criar login * (colocar função de criar cardápio no botão "pronto")

def criar_rest(): #temp = Frame() #temp = home home.destroy() create = Frame(janela) create["bg"] = "#eeddff" janela.title("Cadastro") dado_r = Label(create, text = "\n\nDados do restaurante ", bg = "#eeddff", font = "Calibri 8", fg = "#515151") dado_r.pack()

rest1 = Label(create, text = "Nome: ", bg = "#eeddff") rest1.pack() rest = Entry(create) rest.pack()

cnpj1 = Label(create, text = "CNPJ: ", bg = "#eeddff") cnpj1.pack() cnpj = Entry(create) cnpj.pack()

tel1 = Label(create, text = "Telefone: ", bg = "#eeddff") tel1.pack() tel = Entry(create) tel.pack()

end1 = Label(create, text = "Endereço: ", bg = "#eeddff") end1.pack() end = Entry(create) end.pack()

info1 = Label(create, text = "Informações adicionais: ", bg = "#eeddff") info1.pack() info = Entry(create) info.pack()

dado_u = Label(create, text = "\n\nDados do usuário ", bg = "#eeddff", font = "Calibri 8", fg = "#515151") dado_u.pack()

usuario1 = Label(create, text = "Nome do usuário: ", bg = "#eeddff") usuario1.pack() us1 = Entry(create) us1.pack()

senha1 = Label(create, text = "Senha: ", bg = "#eeddff") senha1.pack() se1 = Entry(create, show = '*') se1.pack()

nsenha1 = Label(create, text = "Redigite a senha: ", bg = "#eeddff") nsenha1.pack() nse1 = Entry(create, show = '*') nse1.pack()

restricao = Label(create, text = "*Mínimo de 8 caracteres; diferencia maiúsculas de minúsculas\n", font = "Calibri 8", fg = "#515151", bg = "#eeddff") restricao.pack()

def valida() : user = us1.get() password = se1.get() npassword = nse1.get() if len(password) >= 8: if password == npassword: arquivo = open("login.txt", 'a') arquivo.write(user + ' ' + password + '\n') arquivo.close() ok = Label(create, text = "Bem vindo!", bg = "#eeddff") ok.pack() else: errou = Label(create, text = "Ahh, não! Algo está errado!", bg = "#eeddff") errou.pack() finish = Button(create, text = "Pronto", font = "Calibri 10 bold", bg = "#4f8c56", fg = "white", relief = "flat", command = valida) finish.pack() create.pack() #temp.pack()

  1. --------------------------- Tela categorias *

s = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sushi.gif") sushi = s.subsample(2, 2) p = PhotoImage(file = "/root/Larissa/ThinkAboutEat/pizza.gif") pz = p.subsample(2, 2) san = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sanduiche.gif") sanduba = san.subsample(2, 2) c = PhotoImage(file = "/root/Larissa/ThinkAboutEat/sopa.gif") caldo = c.subsample(2, 2) f = PhotoImage(file = "/root/Larissa/ThinkAboutEat/fastfood.gif") ff = f.subsample(2, 2) h = PhotoImage(file = "/root/Larissa/ThinkAboutEat/hotdog.gif") hot = h.subsample(2, 2) def categoria(): tela_c = Frame(janela) tela_c["bg"] = "#eeddff" home.destroy() comida_japonesa = Button(tela_c, text = "COMIDA JAPONESA", image = sushi, compound = "left", font = "Calibri 15 bold", bg = "#395061", fg = "white", width = 250) comida_japonesa.pack() pizza = Button(tela_c, text = "PIZZA", image = pz, compound = "right", font = "Calibri 15 bold", bg = "#2cb69d", fg = "white", width = 250) pizza.pack() sanduiche = Button(tela_c, text = "SANDUÍCHES", image = sanduba, compound = "left", font = "Calibri 15 bold", bg = "#6cbbe6", fg = "white", width = 250) sanduiche.pack() caldos = Button(tela_c, text = "CALDOS", image = caldo, compound = "right", font = "Calibri 15 bold", bg = "#fed87a", fg = "white", width = 250) caldos.pack() fastfood = Button(tela_c, text = "FAST FOOD", image = ff, compound = "left", font = "Calibri 15 bold", bg = "#2a4350", fg = "white", width = 250) fastfood.pack() hotdog = Button(tela_c, text = "CACHORRO-QUENTE", image = hot, compound = "right", font = "Calibri 15 bold", bg = "#23a487", fg = "white", width = 250) hotdog.pack() tela_c.pack()


  1. --------------------------- Home *

home = Frame(janela) home["bg"] = "#eeddff" c = PhotoImage(file = "/root/Larissa/ThinkAboutEat/pedido.gif") cestinha = c.subsample(2, 2) ch = PhotoImage(file = "/root/Larissa/ThinkAboutEat/tenho.gif") chef = ch.subsample(2, 2) novo_rest = Button(home, text = "Adicionar restaurante", bg = "white", font = "Calibri 11", relief = "flat", command = criar_rest) pedido = Button(home, image = cestinha, compound = "left", text = "Fazer pedido", font = "Calibri 11", bg = "white", relief = "flat", command = categoria) tenho = Button(home, image = chef, compound = "left", bg = "white", text = "Já tenho um restaurante", font = "Calibri 11", relief = "flat") pedido.pack() novo_rest.pack() tenho.pack() home.pack()

janela.mainloop()





% 16/06/2017 00:49

  1. ----------------------------- Deleta o restaurante

def delete_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') k = -2; for linha in texto: lista = linha.split() if lista[0] == nome: k = -1 if k != -2: k+=1 if k == -1: arquivo.writelines(linha) if k == 4: k = -1 arquivo.close()

  1. ------------------------------------ Adiciona algo ao cardápio

def add_card(): nome = input() tipo = input() novo = input() preco = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -1 for linha in texto: lista = linha.split() if lista[0] == nome: g = 0 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 if g != -1: g+=1 if g == h: k = len(linha) linha += novo linha += ' ' linha += preco linha += ' ' arquivo.writelines(linha) arquivo.close()

  1. ---------------------- Deleta algo do cardápio

def del_card(): rest = input() tipo = input() comida = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() arquivo.close() arquivo = open('dados.txt', 'w') h = 0 g = -2 for linha in texto: lista = linha.split() if lista[0] == rest: g = -1 if tipo == 'entrada': h = 1 elif tipo == 'principal': h = 2 elif tipo == 'sobremesa': h = 3 else: h = 4 v = 0 u = 0 lista2 = [] if g != -2: g+=1 if g == h: s = u = 1 lista1 = linha.split() for i in lista1: if i == comida: v = 1 elif v == 1: v = 0 else: lista2.append(i+' ') lista2.append('\n') if u == 1: arquivo.writelines(lista2) else: arquivo.writelines(linha) arquivo.close()


  1. ------------------------ Le as informações para criar o restaurante

def read(): lista = [] nome = input() lista.append(nome+' ') cnpj = input() lista.append(cnpj+' ') endereco = input() lista.append(endereco+' ') telefone = input() lista.append(telefone+'\n') return lista

  1. --------------------------- Criar Restaurante

def criar_rest(): restaurante = read() arquivo = open('dados.txt', 'a') arquivo.writelines(restaurante) entrada = input() precoe = input() principal = input() precop = input() sobremesa = input() precos = input() bebida = input() precob = input() en = [] en.append(entrada+' ') en.append(precoe+'\n') pri = [] pri.append(principal+' ') pri.append(precop+'\n') sob = [] sob.append(sobremesa+' ') sob.append(precos+'\n') be = [] be.append(bebida+' ') be.append(precob+'\n') arquivo.writelines(en) arquivo.writelines(pri) arquivo.writelines(sob) arquivo.writelines(be) arquivo.close()

  1. ------------------- Procurar Restaurante

def procurar_rest(): nome = input() arquivo = open('dados.txt', 'r') texto = arquivo.readlines() j = 0 for i in texto: lista = i.split() if lista[0] == nome: print(lista) j = 1 break if j == 0: print('Restaurante nao encontrado') arquivo.close()

criar_rest() print("Procure: ") procurar_rest() print("Adicione cardapio: ") add_card() print("Delete cardapio: ") del_card() print("Delete rest: ") delete_rest()

</syntaxhighlight>