-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate.py
More file actions
383 lines (322 loc) · 11.2 KB
/
Copy pathUpdate.py
File metadata and controls
383 lines (322 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# CRIAR client_secret.json
# https://console.developers.google.com/start/api?id=calendar
from __future__ import print_function
import datetime
import os.path
import pickle
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import speech_recognition as sr #importa biblioteca speech_recognition
import os #importa biblioteca do sistema operacional
import pytz
import json
import requests
from googletrans import Translator
recognizer = sr.Recognizer() #inicializa reconhecimento de voz
microphone = sr.Microphone() #inicializa microphone
clear = lambda: os.system('cls')
#variaveis Globais
SCOPES = ['https://www.googleapis.com/auth/calendar.events']
dayS = ["segunda", "terça", "quarta", "quinta", "sexta", "sabado", "domingo"]
APPLICATION_NAME = 'Google Calendar API Python Quickstart'
MESES = ["janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", \
"setembro", "outubro", "novembro", "dezembro"]
dayNUM = ["um", "dois", "três", "quatro", "cinco", "seis", "sete", "oito", "nove", "dez", \
"onze", "doze", "treze", "quatorze", "quinze", "dezesseis", "dezessete", \
"dezoito", "dezenove", "vinte", "vinte e um", "vinte e dois", "vinte e três" \
"vinte e quatro", "vinte e cinco", "vinte e seis", "vinte e sete", \
"vinte e oito", "vinte e nove", "trinta", "trinta e um"]
#reconhecimento de Voz
def reconhecimento():
with microphone as source:
recognizer.adjust_for_ambient_noise(source) #calibra o microfone
audio = recognizer.listen(source) #escuta o microfone
try:
retornoAudio = recognizer.recognize_google(audio,language='pt-BR') #interpreta o audio utilizando o idioma português brasileiro
except:
print("repita novamente...")
retornoAudio = reconhecimento()
with open("outputs.txt","w") as arquivo: #abre arquivo 'outuputs.txt' para modo escrita
arquivo.write(retornoAudio) # escreve no arquivo o retorno do audio
return retornoAudio
#autenticação de Usuário
def autenticacao_google():
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('calendar', 'v3', credentials=creds)
return service
#lista Eventos
def eventos(day, service):
# Call the Calendar API
date = datetime.datetime.combine(day, datetime.datetime.min.time())
end_date = datetime.datetime.combine(day, datetime.datetime.max.time())
utc = pytz.UTC
date_utc = date.astimezone(utc)
end_date_utc = end_date.astimezone(utc)
events_result = service.events().list(calendarId='primary',
timeMin=date_utc.isoformat(),
timeMax=end_date_utc.isoformat(),
singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('Não existem compromissos neste dia.')
input("Pressione uma tecla para continuar...")
else:
clear()
lin()
print("Listando Eventos ")
print("Inicio:", date)
print("Fim:", end_date)
for event in events:
lin()
print("Titulo:"+ event['summary'])
print("Data e Horário: "+ event['start'].get('dateTime'))
lin()
print("")
editarEventos(events, service)
#reconhece uma palabvra chave para eventos no mes
def day(text):
text = text.lower()
today = datetime.date.today()
if text.count("hoje") > 0:
return today
day = -1
day_of_week = -1
month = -1
year = today.year
for word in text.split():
if word in MESES:
month = MESES.index(word) + 1 # procura pelo nome do mês
elif word in dayS:
day_of_week = dayS.index(word) # procura pelo nome do day
elif word.isdigit():
day = int(word)
else:
for nume in dayNUM:
found = word.find(nume)
if found > 0:
try :
day = int(word[:found])
except:
pass
if month < today.month and month != -1: # condição para verificar year atual
year = year+1
if day < today.day and month == -1 and day != -1: #condição para verificar mes
month = month + 1
if month == -1 and day == -1 and day_of_week != -1:
current_day_of_week = today.weekday()
dif = day_of_week - current_day_of_week
if dif < 0:
dif += 7
if text.count("next") >= 1:
dif += 7
return today + datetime.timedelta(dif)
return datetime.date(month=month, day=day, year=year)
def hours(text):
horas = text.split(' ')
return horas[0]+':00:00'
def editarEventos(events, service):
lin()
print('Deseja editar algum evento')
print('SIM / NÃO')
lin()
inicio = reconhecimento().lower()
if inicio == 'sim':
lin()
print("Editando Eventos")
lin()
print("Escolha um titulo")
titulo = reconhecimento().lower()
print(titulo.lower())
lin()
encontrado = False
for event in events:
if (event['summary'].lower() == titulo):
editar(event, service)
encontrado = True
if (encontrado == False):
lin()
print("Evento não encontrado!")
editarEventos(events, service)
def editar(event, service):
print("Escolha um novo titulo")
titulo = reconhecimento().lower()
print(titulo.lower())
lin()
print("Data Inicio")
dateI = reconhecimento().capitalize()
print(dateI)
print('Data Fim')
dateF = reconhecimento().capitalize()
print(dateF)
lin()
print('Hora inicio')
horaInicio = reconhecimento().capitalize()
print(horaInicio)
lin()
print('Hora Fim')
horaFim = reconhecimento().capitalize()
print(horaFim)
lin()
event['summary'] = titulo
event['start'] = {
'dateTime': '{}'.format(day(dateI)) + 'T'+ hours(horaInicio),
'timeZone': 'Brazil/East',
}
event['end'] = {
'dateTime': '{}'.format(day(dateF)) + 'T'+ hours(horaFim),
'timeZone': 'Brazil/East',
}
updated_event = service.events().update(calendarId='primary', eventId=event['id'], body=event).execute()
print('Evento Atualizado...', updated_event['updated'])
input("Pressione uma tecla para continuar...")
#linha
def lin():
print('-'*30)
def criar(service):
print("Titulo:")
tit = reconhecimento().capitalize()
print(tit)
lin()
print("Endereço:")
ende = reconhecimento().capitalize()
print(ende)
lin()
print("Descrição")
desc = reconhecimento().capitalize()
print(desc)
lin()
print("Data Inicio")
dateI = reconhecimento().capitalize()
print(dateI)
lin()
print('Data Fim')
dateF = reconhecimento().capitalize()
print(dateF)
lin()
print("Hora inicio")
horaInicio = reconhecimento().capitalize()
print(horaInicio)
lin()
print('Hora Fim')
horaFim = reconhecimento().capitalize()
print(horaFim)
lin()
event = {
'summary': '{}'.format(tit),
'location': '{}'.format(ende),
'description': '{}'.format(desc),
'start': {
'dateTime': '{}'.format(day(dateI)) + 'T'+ hours(horaInicio),
'timeZone': 'Brazil/East',
},
'end': {
'dateTime': '{}'.format(day(dateF)) + 'T'+ hours(horaFim),
'timeZone': 'Brazil/East',
},
}
event = service.events().insert(calendarId='primary', body=event).execute()
print ('Compromisso agendado: %s' % (event.get('htmlLink')))
def web():
translator = Translator()
r = requests.get('https://r4u.herokuapp.com/getFilme/4')
if r.status_code == 200:
reddit_data = json.loads(r.content)
u = reddit_data['filme']
o = requests.get('http://www.omdbapi.com/?t={}&apikey=ed2baf'.format(u))
reddit2_data = json.loads(o.content)
lin()
print("Titulo:")
print(reddit2_data['Title'])
print('')
lin()
print('Lançamento:')
print(reddit2_data['Released'])
print('')
lin()
print('Genero: ')
traduGenre = translator.translate(reddit2_data['Genre'], dest='pt')
print(traduGenre.text)
print('')
lin()
print('Duração: ')
print(reddit2_data['Runtime'])
print('')
lin()
print('Sinopse: ')
traduPLot = translator.translate(reddit2_data['Plot'], dest='pt')
print(traduPLot.text)
print('')
lin()
else:
print('Erro')
return web
autenticacao_google()
lin()
lin()
print("Iniciando PLIINB")
lin()
print("")
print("")
lin()
SERVICE = autenticacao_google()
print("Bem vindo, PLIINB iniciado.")
lin()
sair = False
while not sair:
clear()
print("")
print("")
lin()
print("Como posso ajudar ?")
print("Escolha um comando")
lin()
print("ABRIR, SAIR")
lin()
inicio = reconhecimento().lower()
if inicio == 'abrir':
lin()
print("Essas são as Opções disponíveis: ")
lin()
print("Criar Evento diga (Criar)")
lin()
print("Consultar compromissos diga (consulta)")
lin()
print("Sugestão de Filmes diga (filme)")
lin()
print("Finalizar diga (Sair)")
lin()
text = reconhecimento().lower()
print(text.lower().capitalize())
if text == 'sair':
sair = True
elif text == 'criar':
criar(SERVICE)
elif text == 'filme':
web()
elif text == 'consulta':
print("Qual data deseja consultar ?")
text = reconhecimento().lower()
SERVICE = autenticacao_google()
print(text)
lin()
eventos(day(text), SERVICE)
lin()
elif inicio == 'sair':
sair = True
print("Fechando o Sistema")
else:
print("Comando não reconhecido")