Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 0
  1. def escuta(self, frase=None):
  2. if frase == None:
  3. frase = input('>: ')
  4. frase = str(frase)
  5. if 'executar ' in frase:
  6. return frase
  7. frase = frase.lower()
  8. frase = frase.replace('é','eh')
  9. return frase
  10.  
  11. def pensa(self, frase):
  12. if frase in self.frases:
  13. return self.frases[frase]
  14. if frase == 'aprende':
  15. return 'Digite a frase: '
  16.  
  17. ultimaFrase = self.historico[-1]
  18. if ultimaFrase == 'Olá, qual o seu nome?':
  19. nome = self.pegaNome(frase)
  20. frase = self.respondeNome(nome)
  21. return frase
  22. if ultimaFrase == 'Digite a frase: ':
  23. self.chave = frase
  24. return 'Digite a resposta: '
  25. if ultimaFrase == 'Digite a resposta: ':
  26. resp = frase
  27. self.frases[self.chave] = resp
  28. self.gravaMemoria()
  29. return 'Aprendido'
  30. try:
  31. resp = str(eval(frase))
  32. return resp
  33. except:
  34. pass
  35.  
  36. if frase == 'ajuda':
  37. temChuv = int(input('Então vamos lá! Quanto tempo, em minutos, você gasta debaixo do chuveiro em um dia?:'))
  38.  
  39.  
  40. temVaso = float(input('Beleza! Quantas descargas você costuma dar em um dia?:'))
  41.  
  42.  
  43. tempb = float(input('Ok! Quanto tempo, em minutos, você gasta usando a pia do banheiro em um dia?:'))
  44.  
  45.  
  46. tempc = float(input('Ok! Quanto tempo, em minutos, você gasta usando a pia da cozinha em um dia?:'))
  47.  
  48.  
  49. temTan = float(input('Ok! Quanto tempo, em minutos, você gasta usando o tanquinho, em um dia?'))
  50.  
  51.  
  52. temMaq = float(input('Beleza! Quantas vezes você utiliza a máquina de lavar roupas por semana?:'))
  53.  
  54. LMaq = temMaq * 12
  55. LTan = temTan * 15
  56. Lbanho = temChuv * 6
  57. LVaso = temVaso * 12
  58. Lpb = tempb * 5
  59. Lpc = tempc * 6
  60. TotalpDia = float(Lbanho + LVaso + Lpc + Lpb + LMaq + LTan)
  61. TotalpMes = float(TotalpDia * 31)
  62. AcreDia = (TotalpDia * 3.14 / 1000)
  63. AcreMes = (31 * AcreDia)
  64. conredu = float(AcreMes - 10.54)
  65.  
  66. print('Você consome cerca de {:.2f} litros de água por dia!n'.format(TotalpDia))
  67. print('E em um mês você consome cerca de {:.2f} litros de água!n'.format(TotalpMes))
  68. 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))
  69.  
  70. if TotalpDia > 110.0:
  71. print('A ONU (Organização das Nações Unidas) diz que 110.0 litros por dia são suficientes paran'
  72. 'atender as necessidades básicas de consumo e higiene de uma pessoa. ')
  73.  
  74. print( 'Portanto, caso você reduza seu consumo de água de {:.2f} para 110 litros por dia. Conseguiránuma redução de '
  75. '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))
  76.  
  77. else:
  78. print('Parabéns! Você está dentro do limite do uso diário de água estipulado pela ONU (Organização das Nações Unidas')
  79.  
  80.  
  81. return 'Não entendi'
  82.  
  83. def pegaNome(self, nome):
  84. if 'o meu nome eh ' in nome:
  85. nome = nome[14:]
  86. nome = nome.title()
  87.  
  88. return nome
  89.  
  90. def respondeNome(self, nome):
  91. if nome in self.conhecidos:
  92. frase = 'Eaew '
  93. else:
  94. frase = 'Muito prazer '
  95. self.conhecidos.append(nome)
  96. self.gravaMemoria()
  97. return frase+nome
  98.  
  99. def gravaMemoria(self):
  100. memoria = open(self.nome+'.json', 'w')
  101. json.dump([self.conhecidos, self.frases], memoria)
  102. memoria.close()
  103.  
  104. def fala(self, frase):
  105. if 'executar ' in frase:
  106. comando = frase.replace('executar ','')
  107. try:
  108. s.Popen(comando.lower())
  109. except FileNotFoundError:
  110. s.Popen(['xdg-open',comando])
  111. else:
  112. print(frase)
  113. self.historico.append(frase)
  114.  
  115. def confirmacao (self, *args, **kwargs):
  116. global poppapSound
  117. poppapSound.play()
  118. box = BoxLayout(orientation = 'vertical', padding = 10, spacing = 15)
  119. botoes = BoxLayout(padding = 7, spacing = 7)
  120.  
  121. pop = Popup(title='Deseja mesmo sair?', content=box, size_hint=(None, None), size=(180, 100))
  122.  
  123. sim = Botao(text = 'Sim', on_release = App.get_running_app().stop)
  124. nao = Botao(text = 'Não', on_release = pop.dismiss)
  125.  
  126. botoes.add_widget(sim)
  127. botoes.add_widget(nao)
  128.  
  129. atencao = Image(source = 'atention.png')
  130.  
  131. box.add_widget(atencao)
  132. box.add_widget(botoes)
  133.  
  134. anim = Animation(size=(300,180), duration = 0.1, t = 'out_back')
  135. anim.start(pop)
  136.  
  137. pop.open()
  138. return True
  139.  
  140. def __init__(self, **kwargs):
  141. super(Botao, self).__init__(**kwargs)
  142. self.atualizar()
  143.  
  144. def on_pos(self, *args):
  145. self.atualizar()
  146.  
  147. def on_size(self, *args):
  148. self.atualizar()
  149.  
  150. def on_press(self, *args):
  151. self.cor, self.cor2 = self.cor2, self.cor
  152.  
  153. def on_release(self, *args):
  154. self.cor, self.cor2 = self.cor2, self.cor
  155.  
  156. def on_cor(self, *args):
  157. self.atualizar()
  158.  
  159. def atualizar(self, *args):
  160. self.canvas.before.clear()
  161. with self.canvas.before:
  162. Color(rgba = self.cor)
  163. Ellipse(size = (self.height, self.height), pos = (self.pos))
  164. Ellipse(size = (self.height, self.height), pos = (self.x + self.width - self.height, self.y))
  165. Rectangle(size = (self.width - self.height, self.height), pos = (self.x + self.height/2.0, self.y))
  166.  
  167. def on_pre_enter(self):
  168. self.ids.box.clear_widgets()
  169. self.path = App.get_running_app().user_data_dir+'/'
  170. self.loadData()
  171. Window.bind(on_keyboard = self.voltar)
  172. for tarefa in self.tarefas:
  173. self.ids.box.add_widget(Tarefa(text=tarefa))
  174.  
  175. def voltar(self,window,key, *args):
  176. if key == 27:
  177. App.get_running_app().root.current = 'menu'
  178. App.get_running_app().root.transition.direction = 'right'
  179. return True
  180.  
  181. def on_pre_leave(self):
  182. Window.unbind(on_keyboard = self.voltar)
  183.  
  184. def loadData(self, *args):
  185. try:
  186. with open(self.path+'data.json', 'r') as data:
  187. self.tarefas = json.load(data)
  188. except FileNotFoundError:
  189. pass
  190.  
  191. def saveData(self,*args):
  192. with open(self.path+'data.json', 'w') as data:
  193. json.dump(self.tarefas, data)
  194.  
  195. def removeWidget(self, tarefa):
  196. global poppapSound
  197. poppapSound.play()
  198. texto = tarefa.ids.label.text
  199. self.ids.box.remove_widget(tarefa)
  200. self.tarefas.remove(texto)
  201. self.saveData()
  202.  
  203. def addWidget(self):
  204. global popSound
  205. popSound.play()
  206. texto = self.ids.texto.text
  207. if texto.strip() =='':
  208. pass
  209. else:
  210. self.ids.box.add_widget(Tarefa(text=texto))
  211. self.ids.texto.text = ''
  212. self.tarefas.append(texto)
  213. self.saveData()
  214.  
  215. def mensagem(self, msg, *args):
  216. self.ids.box.add_widget(Tarefa(text=msg))
  217. frase = self.bot.escuta(frase=msg)
  218. resp = self.bot.pensa(frase)
  219. self.bot.fala(resp)
  220. self.ids.box.add_widget(Tarefa(text=resp))
  221. self.ids.texto.text = ''
  222.  
  223. Tarefas:
  224. name:'tarefas'
  225.  
  226. Assistente:
  227. name:'assistente'
  228.  
  229. Image:
  230. source:'logo.png'
  231. size_hint_y:2.3
  232. allow_strech:True
  233.  
  234. Botao:
  235.  
  236. text:'Tarefas'
  237. on_release:app.root.current = 'tarefas'
  238. on_release:app.root.transition.direction = 'right'
  239. Botao:
  240. text:'Assistente'
  241. on_release:app.root.current = 'assistente'
  242. on_release:app.root.transition.direction = 'left'
  243.  
  244. Botao:
  245. text:'Sair'
  246. on_release:root.confirmacao()
  247.  
  248. ActionBar:
  249. ActionView:
  250. ActionPrevious:
  251. title:'Tarefa'
  252. on_release:app.root.current = 'menu'
  253.  
  254.  
  255. ActionButton:
  256. text:'Sair'
  257. on_release:app.stop()
  258.  
  259. ScrollView:
  260. BoxLayout:
  261. id:box
  262. orientation:'vertical'
  263. size_hint_y:None
  264. height:self.minimum_height
  265. color:0,0,0,1
  266.  
  267. BoxLayout:
  268. size_hint_y:None
  269. height:'40sp'
  270. TextInput:
  271. id:texto
  272.  
  273. Button:
  274. text:'+'
  275. size_hint_x:None
  276. width:'40sp'
  277. on_release:root.addWidget()
  278. background_color:(0,1,2,1)
  279.  
  280. Button:
  281. text:'X'
  282. size_hint_x:None
  283. width:'40sp'
  284. on_release:app.root.get_screen('tarefas').removeWidget(root)
  285. background_color:(0,1,2,1)
  286.  
  287. ActionBar:
  288. ActionView:
  289. ActionPrevious:
  290. title:'Assistente'
  291. on_release:app.root.current = 'menu'
  292.  
  293. ActionButton:
  294. text:'Sair'
  295. on_release:app.stop()
  296.  
  297. ScrollView:
  298. BoxLayout:
  299. id:box
  300. orientation:'vertical'
  301. size_hint_y:None
  302. height:self.minimum_height
  303. color:0,0,0,1
  304.  
  305. BoxLayout:
  306. size_hint_y:None
  307. height:'40sp'
  308. TextInput:
  309. id:texto
  310.  
  311. Button:
  312. text:'>'
  313. size_hint_x:None
  314. width:'40sp'
  315. background_color:(0,1,2,1)
  316. on_release:root.mensagem(texto.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement