Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def escuta(self, frase=None):
- if frase == None:
- frase = input('>: ')
- frase = str(frase)
- if 'executar ' in frase:
- return frase
- frase = frase.lower()
- frase = frase.replace('é','eh')
- return frase
- def pensa(self, frase):
- if frase in self.frases:
- return self.frases[frase]
- if frase == 'aprende':
- return 'Digite a frase: '
- ultimaFrase = self.historico[-1]
- if ultimaFrase == 'Olá, qual o seu nome?':
- nome = self.pegaNome(frase)
- frase = self.respondeNome(nome)
- return frase
- if ultimaFrase == 'Digite a frase: ':
- self.chave = frase
- return 'Digite a resposta: '
- if ultimaFrase == 'Digite a resposta: ':
- resp = frase
- self.frases[self.chave] = resp
- self.gravaMemoria()
- return 'Aprendido'
- try:
- resp = str(eval(frase))
- return resp
- except:
- pass
- if frase == 'ajuda':
- temChuv = int(input('Então vamos lá! Quanto tempo, em minutos, você gasta debaixo do chuveiro em um dia?:'))
- temVaso = float(input('Beleza! Quantas descargas você costuma dar em um dia?:'))
- tempb = float(input('Ok! Quanto tempo, em minutos, você gasta usando a pia do banheiro em um dia?:'))
- tempc = float(input('Ok! Quanto tempo, em minutos, você gasta usando a pia da cozinha em um dia?:'))
- temTan = float(input('Ok! Quanto tempo, em minutos, você gasta usando o tanquinho, em um dia?'))
- temMaq = float(input('Beleza! Quantas vezes você utiliza a máquina de lavar roupas por semana?:'))
- LMaq = temMaq * 12
- LTan = temTan * 15
- Lbanho = temChuv * 6
- LVaso = temVaso * 12
- Lpb = tempb * 5
- Lpc = tempc * 6
- TotalpDia = float(Lbanho + LVaso + Lpc + Lpb + LMaq + LTan)
- TotalpMes = float(TotalpDia * 31)
- AcreDia = (TotalpDia * 3.14 / 1000)
- AcreMes = (31 * AcreDia)
- conredu = float(AcreMes - 10.54)
- print('Você consome cerca de {:.2f} litros de água por dia!n'.format(TotalpDia))
- print('E em um mês você consome cerca de {:.2f} litros de água!n'.format(TotalpMes))
- print('Isto representa um acréscimo de cerca de R${:.2f} por dia e R${:.2f} por mês na sua conta de águan'.format(AcreDia, AcreMes))
- if TotalpDia > 110.0:
- print('A ONU (Organização das Nações Unidas) diz que 110.0 litros por dia são suficientes paran'
- 'atender as necessidades básicas de consumo e higiene de uma pessoa. ')
- print( 'Portanto, caso você reduza seu consumo de água de {:.2f} para 110 litros por dia. Conseguiránuma redução de '
- 'cerca de R$ 10.54 na sua conta de água, que passará a ser R${:.2f}, e estará fazendo a sua parte no uso consciente deste recurso.'.format(TotalpDia, conredu))
- else:
- print('Parabéns! Você está dentro do limite do uso diário de água estipulado pela ONU (Organização das Nações Unidas')
- return 'Não entendi'
- def pegaNome(self, nome):
- if 'o meu nome eh ' in nome:
- nome = nome[14:]
- nome = nome.title()
- return nome
- def respondeNome(self, nome):
- if nome in self.conhecidos:
- frase = 'Eaew '
- else:
- frase = 'Muito prazer '
- self.conhecidos.append(nome)
- self.gravaMemoria()
- return frase+nome
- def gravaMemoria(self):
- memoria = open(self.nome+'.json', 'w')
- json.dump([self.conhecidos, self.frases], memoria)
- memoria.close()
- def fala(self, frase):
- if 'executar ' in frase:
- comando = frase.replace('executar ','')
- try:
- s.Popen(comando.lower())
- except FileNotFoundError:
- s.Popen(['xdg-open',comando])
- else:
- print(frase)
- self.historico.append(frase)
- def confirmacao (self, *args, **kwargs):
- global poppapSound
- poppapSound.play()
- box = BoxLayout(orientation = 'vertical', padding = 10, spacing = 15)
- botoes = BoxLayout(padding = 7, spacing = 7)
- pop = Popup(title='Deseja mesmo sair?', content=box, size_hint=(None, None), size=(180, 100))
- sim = Botao(text = 'Sim', on_release = App.get_running_app().stop)
- nao = Botao(text = 'Não', on_release = pop.dismiss)
- botoes.add_widget(sim)
- botoes.add_widget(nao)
- atencao = Image(source = 'atention.png')
- box.add_widget(atencao)
- box.add_widget(botoes)
- anim = Animation(size=(300,180), duration = 0.1, t = 'out_back')
- anim.start(pop)
- pop.open()
- return True
- def __init__(self, **kwargs):
- super(Botao, self).__init__(**kwargs)
- self.atualizar()
- def on_pos(self, *args):
- self.atualizar()
- def on_size(self, *args):
- self.atualizar()
- def on_press(self, *args):
- self.cor, self.cor2 = self.cor2, self.cor
- def on_release(self, *args):
- self.cor, self.cor2 = self.cor2, self.cor
- def on_cor(self, *args):
- self.atualizar()
- def atualizar(self, *args):
- self.canvas.before.clear()
- with self.canvas.before:
- Color(rgba = self.cor)
- Ellipse(size = (self.height, self.height), pos = (self.pos))
- Ellipse(size = (self.height, self.height), pos = (self.x + self.width - self.height, self.y))
- Rectangle(size = (self.width - self.height, self.height), pos = (self.x + self.height/2.0, self.y))
- def on_pre_enter(self):
- self.ids.box.clear_widgets()
- self.path = App.get_running_app().user_data_dir+'/'
- self.loadData()
- Window.bind(on_keyboard = self.voltar)
- for tarefa in self.tarefas:
- self.ids.box.add_widget(Tarefa(text=tarefa))
- def voltar(self,window,key, *args):
- if key == 27:
- App.get_running_app().root.current = 'menu'
- App.get_running_app().root.transition.direction = 'right'
- return True
- def on_pre_leave(self):
- Window.unbind(on_keyboard = self.voltar)
- def loadData(self, *args):
- try:
- with open(self.path+'data.json', 'r') as data:
- self.tarefas = json.load(data)
- except FileNotFoundError:
- pass
- def saveData(self,*args):
- with open(self.path+'data.json', 'w') as data:
- json.dump(self.tarefas, data)
- def removeWidget(self, tarefa):
- global poppapSound
- poppapSound.play()
- texto = tarefa.ids.label.text
- self.ids.box.remove_widget(tarefa)
- self.tarefas.remove(texto)
- self.saveData()
- def addWidget(self):
- global popSound
- popSound.play()
- texto = self.ids.texto.text
- if texto.strip() =='':
- pass
- else:
- self.ids.box.add_widget(Tarefa(text=texto))
- self.ids.texto.text = ''
- self.tarefas.append(texto)
- self.saveData()
- def mensagem(self, msg, *args):
- self.ids.box.add_widget(Tarefa(text=msg))
- frase = self.bot.escuta(frase=msg)
- resp = self.bot.pensa(frase)
- self.bot.fala(resp)
- self.ids.box.add_widget(Tarefa(text=resp))
- self.ids.texto.text = ''
- Tarefas:
- name:'tarefas'
- Assistente:
- name:'assistente'
- Image:
- source:'logo.png'
- size_hint_y:2.3
- allow_strech:True
- Botao:
- text:'Tarefas'
- on_release:app.root.current = 'tarefas'
- on_release:app.root.transition.direction = 'right'
- Botao:
- text:'Assistente'
- on_release:app.root.current = 'assistente'
- on_release:app.root.transition.direction = 'left'
- Botao:
- text:'Sair'
- on_release:root.confirmacao()
- ActionBar:
- ActionView:
- ActionPrevious:
- title:'Tarefa'
- on_release:app.root.current = 'menu'
- ActionButton:
- text:'Sair'
- on_release:app.stop()
- ScrollView:
- BoxLayout:
- id:box
- orientation:'vertical'
- size_hint_y:None
- height:self.minimum_height
- color:0,0,0,1
- BoxLayout:
- size_hint_y:None
- height:'40sp'
- TextInput:
- id:texto
- Button:
- text:'+'
- size_hint_x:None
- width:'40sp'
- on_release:root.addWidget()
- background_color:(0,1,2,1)
- Button:
- text:'X'
- size_hint_x:None
- width:'40sp'
- on_release:app.root.get_screen('tarefas').removeWidget(root)
- background_color:(0,1,2,1)
- ActionBar:
- ActionView:
- ActionPrevious:
- title:'Assistente'
- on_release:app.root.current = 'menu'
- ActionButton:
- text:'Sair'
- on_release:app.stop()
- ScrollView:
- BoxLayout:
- id:box
- orientation:'vertical'
- size_hint_y:None
- height:self.minimum_height
- color:0,0,0,1
- BoxLayout:
- size_hint_y:None
- height:'40sp'
- TextInput:
- id:texto
- Button:
- text:'>'
- size_hint_x:None
- width:'40sp'
- background_color:(0,1,2,1)
- on_release:root.mensagem(texto.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement