Last active
March 4, 2018 13:36
-
-
Save dalraf/91e830d15020f5131f22a2cedf052a0e to your computer and use it in GitHub Desktop.
Qpython teste
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import urllib.request as req | |
| import re | |
| import sl4a | |
| class Cotacao: | |
| def __get_cotacao(self, url, regex='^.*nacional" value="([0-9,]+)"'): | |
| pagina = req.urlopen(url) | |
| s = pagina.read().decode('utf-8') | |
| m = re.match(regex, s, re.DOTALL) | |
| if m: | |
| return float(m.group(1).replace(',', '.')) | |
| else: | |
| return 0 | |
| def dolar(self): | |
| return self.__get_cotacao('http://dolarhoje.com/') | |
| def euro(self): | |
| return self.__get_cotacao('http://eurohoje.com/') | |
| def libra(self): | |
| return self.__get_cotacao('http://librahoje.com/') | |
| def showcotacao() : | |
| cotacao = Cotacao() | |
| droid = sl4a.Android() | |
| droid.ttsSpeak('Hoje estamos com as seguintes cotações de moedas estrangeiras') | |
| droid.ttsSpeak('Dólar: R${0:.2f}'.format(cotacao.dolar())) | |
| droid.ttsSpeak('Euro: R${0:.2f}'.format(cotacao.euro())) | |
| droid.ttsSpeak('Libra: R${0:.2f}'.format(cotacao.libra())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sl4a | |
| import time | |
| droid = sl4a.Android() | |
| def speak(text): | |
| droid.ttsSpeak(text) | |
| while droid.ttsIsSpeaking()[1] == True: | |
| time.sleep(1) | |
| def listen(): | |
| return droid.recognizeSpeech('Fale agora',None,None) | |
| def login(): | |
| speak('O que você deseja?') | |
| try: | |
| phrase = listen().result.lower() | |
| except: | |
| speak('Não entendi o que você disse') | |
| exit(0) | |
| if 'cotação' in phrase: | |
| import cotacao | |
| cotacao.showcotacao() | |
| elif 'ip externo' in phrase: | |
| import ip | |
| ip.ipexterno() | |
| else: speak('Comando não reconhecido') | |
| exit(0) | |
| login() | |
| exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ipgetter | |
| import sl4a | |
| def ipexterno(): | |
| myip = ipgetter.myip() | |
| droid = sl4a.Android() | |
| ipsplit = myip.split(".") | |
| textspeak = "O endereço é " | |
| for ip in ipsplit: | |
| if ip != ipsplit[-1]: | |
| textadd = " ponto " | |
| else: | |
| textadd = "" | |
| textspeak = textspeak + ip + textadd | |
| droid.ttsSpeak(textspeak) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment