-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdaForLex.txt
More file actions
1070 lines (869 loc) · 36.8 KB
/
lambdaForLex.txt
File metadata and controls
1070 lines (869 loc) · 36.8 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import print_function
import math
import dateutil.parser
import datetime
from datetime import datetime
import time
import os
import boto3
from boto3.dynamodb.conditions import Key, Attr
import json
import decimal
#import wikipedia
#import wikiIntent
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
return str(o)
return super(DecimalEncoder, self).default(o)
date = datetime.now()
date = date.strftime('%Y/%b/%d/%H/%M/%S/%f')
# print(type(date))
print(date)
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('SingPrim')
table2 = dynamodb.Table('AthenaEvent')
uniId=datetime.now().strftime("%y-%m-%d-%H-%M-%S")
""" --- Helpers to build responses which match the structure of the necessary dialog actions --- """
def get_slots(intent_request):
return intent_request['currentIntent']['slots']
def elicit_slot(session_attributes, intent_name, slots, slot_to_elicit, message):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'ElicitSlot',
'intentName': intent_name,
'slots': slots,
'slotToElicit': slot_to_elicit,
'message': message
}
}
def close(session_attributes, fulfillment_state, message):
response = {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Close',
'fulfillmentState': fulfillment_state,
'message': message
}
}
return response
def delegate(session_attributes, slots):
return {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Delegate',
'slots': slots
}
}
'''def addeventfunc(intent_request):
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Hi there how may I help you in add event intent' })
'''
#-------------------------------------------------------------------------------------
def parse_int(n):
try:
return int(n)
except ValueError:
return float('nan')
def build_validation_result(is_valid, violated_slot, message_content):
if message_content is None:
return {
"isValid": is_valid,
"violatedSlot": violated_slot,
}
return {
'isValid': is_valid,
'violatedSlot': violated_slot,
'message': {'contentType': 'PlainText', 'content': message_content}
}
def isvalid_date(date):
try:
dateutil.parser.parse(date)
return True
except ValueError:
return False
#--------------VALIDATION FUNCTIONS-----------------------------------------------------------------------------------------------
def validate_addevent(stime,sdate,etime,edate):
if stime is not None:
if not isvalid_date(stime):
return build_validation_result(False,'Time', 'Kindly enter time in valid format. Eg: 2 pm')
if sdate is not None:
if not isvalid_date(sdate):
return build_validation_result(False,'Time', 'Kindly enter date in valid format. Eg: 2 pm')
if etime is not None:
if not isvalid_date(etime):
return build_validation_result(False,'Time', 'Kindly enter date in valid format. Eg: 2 pm')
if edate is not None:
if not isvalid_date(edate):
return build_validation_result(False,'Time', 'Kindly enter date in valid format. Eg: 2 pm')
if edate is not None and sdate is not None:
if edate<sdate:
return build_validation_result(False,'EndDate', 'Kindly enter an end date later or same day as start date.')
if edate is not None and sdate is not None and etime is not None and stime is not None:
if edate == sdate:
if etime <= stime:
return build_validation_result(False,'EndTime', 'Kindly enter a time later than start time.')
return build_validation_result(True,None,None)
def validate_addtask(priority,deadline):
priority_type=['low','medium','high']
if priority is not None and priority.lower() not in priority_type:
return build_validation_result(False,
'Priority',
'We do not support {} priority. Please select from [low, medium, high].'.format(priority))
if deadline is not None:
#today=datetime.date.today()
today=datetime.date(datetime.now()).today()
s=""
s=str(today)
if deadline<s:
return build_validation_result(False,'Deadline', 'Kindly enter a deadline no earlier than today.')
return build_validation_result(True,None,None)
#-----------------------Small talk Intent specific functions----------------------------------------------------------------------------------
def greetfunc(intent_request):
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Hi there how may I help you' })
def salutfunc(intent_request):
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Bye! Hope to see you again real soon.' })
#-----------------------EVENT Intent specific functions----------------------------------------------------------------------------------
def addeventfunc(intent_request):
summary=get_slots(intent_request)["Summary"]
stime=get_slots(intent_request)["StartTime"]
sdate=get_slots(intent_request)["StartDate"]
etime=get_slots(intent_request)["EndTime"]
edate=get_slots(intent_request)["EndDate"]
email=get_slots(intent_request)["email"]
flagg=0
source=intent_request['invocationSource']
if source == 'DialogCodeHook':
slots=get_slots(intent_request)
validation_result = validate_addevent(stime,sdate,etime,edate)
if not validation_result['isValid']:
slots[validation_result['violatedSlot']] = None
return elicit_slot(intent_request['sessionAttributes'],
intent_request['currentIntent']['name'],
slots,
validation_result['violatedSlot'],
validation_result['message'])
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
if(summary is not None and stime is not None and sdate is not None and etime is not None and edate is not None and email is not None):
flagg=1
print("unique ID is, ",uniId)
table2.put_item(
Item = {
'id': uniId,
'username': email,
'summary':summary,
'startDate':sdate,
'startTime':stime,
'endDate':edate,
'endTime':etime
}
)
if(flagg==0):
return delegate(output_session_attributes,get_slots(intent_request))
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content':'Thanks, the event \"{}\" has been added to your calendar'.format(summary)})
def listeventsfunc(intent_request):
# fe = Attr('username').eq('str306');
# ean = { "#un": "username" }
# esk = None
# response = table.scan(
# FilterExpression=fe
# )
flagg=0
email=get_slots(intent_request)["email"]
# if email is not None:
# flagg=1
#if flag==1:
fe = Attr('username').eq(email);
pe ="id,endDate,endTime,startDate,startTime,summary,username";
ean = { "#un": "username" }
esk = None
response = table2.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
for i in response['Items']:
if 'summary' not in i: #skip tasks
continue
#x.append(json.dumps(i, cls=DecimalEncoder))
#x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
temp=json.dumps(i)
temparr=temp.split(",")
temparr1=temparr[1].split(":") #contains summary of event
temparr2=temparr[3].split(":") #contains end date
temparr3=temparr[2].split(":") #contains end time
stripstring=temparr1[1].strip(' ') #summary
stripstring=stripstring.strip('\"')
stripstring2=temparr2[1].strip(' ') #end date
stripstring2=stripstring2.strip('\"')
stripstring3=temparr3[1].strip(' ') #end time hour
stripstring3=stripstring3.strip('\"')
stripstring4=temparr3[2].strip(' ') #end time minute
stripstring4=stripstring4.strip('\"')
skyfall=stripstring2+' '+stripstring3+':'+stripstring4
sf=datetime.strptime(skyfall,'%Y-%m-%d %H:%M')
curr=datetime.now()
if curr>sf:
continue
x.append(stripstring)
#x.append(i)
if not x:
str1="there are no events for you."
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Sorry! {}'.format(str1)})
else:
str1=' , '.join(str(e) for e in x)
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'The events currently active are : {}'.format(str1)})
def listcompletedeventfunc(intent_request):
email=get_slots(intent_request)["email"]
flagg=0
#email=get_slots(intent_request)["email"]
# if email is not None:
# flagg=1
#if flag==1:
fe = Attr('username').eq(email);
pe ="id,endDate,endTime,startDate,startTime,summary,username";
ean = { "#un": "username" }
esk = None
response = table2.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
for i in response['Items']:
if 'summary' not in i: #skip tasks
continue
#x.append(json.dumps(i, cls=DecimalEncoder))
#x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
temp=json.dumps(i)
temparr=temp.split(",")
temparr1=temparr[1].split(":") #contains summary of event
temparr2=temparr[3].split(":") #contains end date
temparr3=temparr[2].split(":") #contains end time
stripstring=temparr1[1].strip(' ') #summary
stripstring=stripstring.strip('\"')
stripstring2=temparr2[1].strip(' ') #end date
stripstring2=stripstring2.strip('\"')
stripstring3=temparr3[1].strip(' ') #end time hour
stripstring3=stripstring3.strip('\"')
stripstring4=temparr3[2].strip(' ') #end time minute
stripstring4=stripstring4.strip('\"')
skyfall=stripstring2+' '+stripstring3+':'+stripstring4
sf=datetime.strptime(skyfall,'%Y-%m-%d %H:%M')
curr=datetime.now()
if curr<sf:
continue
x.append(stripstring)
#x.append(i)
if not x:
str1="you have not completed any events recently."
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Sorry! {}'.format(str1)})
else:
str1=' , '.join(str(e) for e in x)
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'The events recently concluded are : {}'.format(str1)})
def deleteeventfunc(intent_request):
fname=get_slots(intent_request)["EventName"]
email=get_slots(intent_request)["email"]
flagg=0
source = intent_request['invocationSource']
if source == 'DialogCodeHook':
slots = get_slots(intent_request)
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
if(fname is not None and email is not None):
flagg=1
fe = Attr('username').eq(email);
pe = "id,endDate,endTime,startDate,startTime,summary,username";
ean = { "#un": "username" }
esk = None
response = table2.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
idd=""
for i in response['Items']: #to skip events and include only tasks
if 'summary' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[1].split(":") #event name
temparr3=temparr[6].split(":") #id of the task we are searching for
stripstring=temparr2[1].strip(' ')
stripstring=stripstring.strip('}"')
stripstring=stripstring.strip('\"')
#print(temparr3[1],':',stripstring)
#print(temparr2[1])
#temparr3=temparr[1].split(":")
#stripstring=temparr3[1].strip(' ')
#stripstring=stripstring.strip('\"')
var=fname
if stripstring == var: #if eventName is equal to user entered eventName
stripstring2=temparr3[1].strip(' ')
stripstring2=stripstring2.strip('}')
stripstring2=stripstring2.strip('\"')
idd=stripstring2
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('}')
stripstring2=stripstring2.strip('\"')
x.append(i)
str1 = '\n'.join(str(e) for e in x)
# print("i am here outside")
# print('idd ',idd)
# print('stripstring ',stripstring)
# print('var ',var)
print(x)
if idd:
print("i am here")
print(idd)
table2.delete_item(
Key = {
'id': idd
})
else:
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'The event \'{}\' is not present in your calendar. Please say \" List Events \" to know which events you currently have'.format(fname) })
if(flagg==0):
return delegate(output_session_attributes,get_slots(intent_request))
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Deleting the event {} and waiting on dynamo db'.format(fname) })
#-----------------------TASK Intent specific functions----------------------------------------------------------------------------------
def addtaskfunc(intent_request):
name=get_slots(intent_request)["Name"]
description=get_slots(intent_request)["Description"]
priority=get_slots(intent_request)["Priority"]
deadline=get_slots(intent_request)["Deadline"]
completed=False
email=get_slots(intent_request)["email"]
flagg=0
source = intent_request['invocationSource']
if source == 'DialogCodeHook':
slots = get_slots(intent_request)
validation_result = validate_addtask(priority,deadline)
if not validation_result['isValid']:
slots[validation_result['violatedSlot']] = None
return elicit_slot(intent_request['sessionAttributes'],
intent_request['currentIntent']['name'],
slots,
validation_result['violatedSlot'],
validation_result['message'])
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
#here to add task
if(name is not None and description is not None and priority is not None and deadline is not None and email is not None):
flagg=1
table.put_item(
Item = {
'username': email,
'types': 'task',
'id': date,
'description': description,
'priority': priority,
'deadline': deadline,
'taskName': name,
'completed': completed
}
)
if(flagg==0):
return delegate(output_session_attributes,get_slots(intent_request))
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content':'Thanks, \' {} \' has been added to your list of tasks'.format(name)})
def listtasksfunc(intent_request):
email=get_slots(intent_request)["email"]
#if email is not None:
fe = Attr('username').eq(email);
pe = "taskName, description, deadline,completed";
ean = { "#un": "username" }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
'''
for i in response['Items']:
if 'taskName' not in i:
continue
x.append(json.dumps(i, cls=DecimalEncoder))
x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
'''
for i in response['Items']:
if 'taskName' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[3].split(":") #contains taskname
temparr1=temparr[0].split(":") #contains flag
#print(temparr2[1],'\n')
#x.append(temparr2[1])
stripstring=temparr1[1].strip(' ')
stripstring=stripstring.strip('\'')
print(stripstring)
if stripstring == 'false':
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('\}')
stripstring2=stripstring2.strip('\"')
x.append(stripstring2)
#str1 = '\n'.join(str(e) for e in x)
if not x:
str1="There are no incomplete tasks for you. You may add new tasks by saying \" add tasks \" "
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Sorry! {}'.format(str1) })
else:
str1=' , '.join(str(e) for e in x)
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'The tasks currently active for you are: {}'.format(str1) })
def listcompletedtasksfunc(intent_request):
email=get_slots(intent_request)["email"]
#if email is not None:
fe = Attr('username').eq(email);
pe = "taskName, description, deadline,completed";
ean = { "#un": "username" }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
'''
for i in response['Items']:
if 'taskName' not in i:
continue
x.append(json.dumps(i, cls=DecimalEncoder))
x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
'''
for i in response['Items']:
if 'taskName' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[3].split(":") #contains taskname
temparr1=temparr[0].split(":") #contains flag
#print(temparr2[1],'\n')
#x.append(temparr2[1])
stripstring=temparr1[1].strip(' ')
stripstring=stripstring.strip('\'')
print(stripstring)
if stripstring == 'true':
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('\}')
stripstring2=stripstring2.strip('\"')
x.append(stripstring2)
#str1 = '\n'.join(str(e) for e in x)
if not x:
str1="There are no incomplete tasks for you. You may add new tasks by saying \" add tasks \" "
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Sorry! {}'.format(str1) })
else:
str1=' , '.join(str(e) for e in x)
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'You recently completed the tasks : {}'.format(str1) })
def listimportanttasksfunc(intent_request):
email=get_slots(intent_request)["email"]
#if email is not None:
fe = Attr('username').eq(email);
pe = "taskName,description,deadline,priority,completed";
ean = { "#un": "username" }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
'''
for i in response['Items']:
if 'taskName' not in i:
continue
x.append(json.dumps(i, cls=DecimalEncoder))
x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
'''
for i in response['Items']:
if 'taskName' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[4].split(":") #contains task name
temparr3=temparr[2].split(":") #contains priority level
temparr1=temparr[0].split(":") #contains completed flag value
stripstring=temparr3[1].strip(' ') #priority
stripstring=stripstring.strip('\"')
stripstring2=temparr1[1].strip(' ') #flag
stripstring2=stripstring2.strip('\"')
stripstring3=temparr2[1].strip(' ') #flag
stripstring3=stripstring3.strip('}')
stripstring3=stripstring3.strip('\"')
var="high"
if stripstring != var:
continue
if stripstring2 == 'true':
continue
#print(temparr2[1])
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('\"')
x.append(stripstring3)
#str1 = '\n '.join(str(e) for e in x)
#str1=' , '.join(str(e) for e in x)
if not x:
str1="You do not have any important tasks. To add an important task, say \" add task \" and set the priority to \" high \" "
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Sorry! {}'.format(str1) })
else:
str1=' , '.join(str(e) for e in x)
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'The important tasks currently active for you are: {}'.format(str1) })
def deletetaskfunc(intent_request):
email=get_slots(intent_request)["email"]
tname=get_slots(intent_request)["TaskName"]
flagg=0
source = intent_request['invocationSource']
if source == 'DialogCodeHook':
slots = get_slots(intent_request)
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
if(tname is not None and email is not None):
flagg=1
fe = Attr('username').eq(email);
pe = "taskName,description,deadline,priority,id";
ean = { "#un": "username" }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
idd=""
for i in response['Items']: #to skip events and include only tasks
if 'taskName' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[4].split(":") #task name
temparr3=temparr[3].split(":") #id of the task we are searching for
stripstring=temparr2[1].strip(' ')
stripstring=stripstring.strip('}"')
stripstring=stripstring.strip('\"')
#print(temparr3[1],':',stripstring)
#print(temparr2[1])
#temparr3=temparr[1].split(":")
#stripstring=temparr3[1].strip(' ')
#stripstring=stripstring.strip('\"')
var=tname
if stripstring == var: #if taskname is equal to user entered taskname
stripstring2=temparr3[1].strip(' ')
stripstring2=stripstring2.strip('\"')
idd=stripstring2
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('\"')
x.append(i)
str1 = '\n'.join(str(e) for e in x)
# print("i am here outside")
# print('idd ',idd)
# print('stripstring ',stripstring)
# print('var ',var)
print(x)
if idd:
print("i am here")
table.delete_item(
Key = {
'id': idd
})
else:
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'The task \'{}\' is not present in your calendar. Please say \" List Task \" to know which tasks you currently have'.format(tname) })
if(flagg==0):
return delegate(output_session_attributes,get_slots(intent_request))
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Deleting the task {} from your calendar'.format(tname) })
def marktaskcompletefunc(intent_request):
tname=get_slots(intent_request)["TaskName"]
email=get_slots(intent_request)["email"]
flagg=0
source = intent_request['invocationSource']
if source == 'DialogCodeHook':
slots = get_slots(intent_request)
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
if(tname is not None and email is not None):
flagg=1
fe = Attr('username').eq(email);
pe = "taskName,description,deadline,priority,id";
ean = { "#un": "username" }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
idd=""
for i in response['Items']: #to skip events and include only tasks
if 'taskName' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[4].split(":") #task name
temparr3=temparr[3].split(":") #id of the task we are searching for
stripstring=temparr2[1].strip(' ')
stripstring=stripstring.strip('}"')
stripstring=stripstring.strip('\"')
#print(temparr3[1],':',stripstring)
#print(temparr2[1])
#temparr3=temparr[1].split(":")
#stripstring=temparr3[1].strip(' ')
#stripstring=stripstring.strip('\"')
var=tname
if stripstring == var: #if taskname is equal to user entered taskname
stripstring2=temparr3[1].strip(' ')
stripstring2=stripstring2.strip('\"')
idd=stripstring2
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('\"')
x.append(i)
str1 = '\n'.join(str(e) for e in x)
# print("i am here outside")
# print('idd ',idd)
# print('stripstring ',stripstring)
# print('var ',var)
print(x)
if idd:
print("i am here")
table.update_item(
Key = {
'id': idd
},
UpdateExpression = 'SET completed = :value1',
ExpressionAttributeValues = {
':value1': True
})
if(flagg==0):
return delegate(output_session_attributes,get_slots(intent_request))
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'Marking the task \' {} \' as completed'.format(tname) })
#-----------------------Create Schedule Intent specific functions----------------------------------------------------------------------------------
def createschedulefunc(intent_request):
email=get_slots(intent_request)["email"]
fe = Attr('username').eq(email);
pe ="id,endDate,endTime,startDate,startTime,summary,username";
ean = { "#un": "username" }
esk = None
#the event part
response = table2.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
y=[]
for i in response['Items']:
if 'summary' not in i: #skip tasks
continue
#x.append(json.dumps(i, cls=DecimalEncoder))
#x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
temp=json.dumps(i)
temparr=temp.split(",")
temparr1=temparr[1].split(":") #contains summary of event
temparr2=temparr[3].split(":") #contains end date
temparr3=temparr[2].split(":") #contains end time
temparr4=temparr[4].split(":") #contains start date
temparr5=temparr[0].split(":") #contains start time
stripstring=temparr1[1].strip(' ') #summary
stripstring=stripstring.strip('\"')
stripstring2=temparr2[1].strip(' ') #end date
stripstring2=stripstring2.strip('\"')
stripstring3=temparr3[1].strip(' ') #end time hour
stripstring3=stripstring3.strip('\"')
stripstring4=temparr3[2].strip(' ') #end time minute
stripstring4=stripstring4.strip('\"')
stripstring5=temparr4[1].strip(' ') #start date
stripstring5=stripstring5.strip('\"')
stripstring6=temparr5[1].strip(' ') #start time hour
stripstring6=stripstring6.strip('\"')
stripstring7=temparr5[2].strip(' ') #start time minutes
stripstring7=stripstring7.strip('\"')
skyfall=stripstring2+' '+stripstring3+':'+stripstring4
dawn=stripstring5+' '+stripstring6+':'+stripstring7
sf=datetime.strptime(skyfall,'%Y-%m-%d %H:%M')
dw=datetime.strptime(dawn,'%Y-%m-%d %H:%M')
curr=datetime.now()
if curr>sf:
continue
if curr>dw and curr<sf:
y.append(stripstring)
if curr.date()==dw.date():
x.append(stripstring)
str1=""
str2=""
if not y:
str1='you do not have any events in progress.'
else:
str1='your events in progress are: '
str1=str1+' , '.join(str(e) for e in y)
if not x:
str2="you do not have any events starting today."
else:
str2='the events starting today are: '
str2=str2+' , '.join(str(e) for e in x)
str3=str1+' '+str2
#the task part
fe = Attr('username').eq(email);
pe = "taskName, description, deadline,completed";
ean = { "#un": "username" }
esk = None
response = table.scan(
FilterExpression=fe,
ProjectionExpression = pe
)
x=[]
'''
for i in response['Items']:
if 'taskName' not in i:
continue
x.append(json.dumps(i, cls=DecimalEncoder))
x.append(print("\n"))
#print(json.dumps(i, cls=DecimalEncoder))
'''
for i in response['Items']:
if 'taskName' not in i:
continue
temp=json.dumps(i)
temparr=temp.split(",")
temparr2=temparr[3].split(":") #contains taskname
temparr1=temparr[0].split(":") #contains flag
#print(temparr2[1],'\n')
#x.append(temparr2[1])
stripstring=temparr1[1].strip(' ')
stripstring=stripstring.strip('\'')
#print(stripstring)
#print("i am out in task")
if stripstring == 'false': #include only incomplete tasks
stripstring2=temparr2[1].strip(' ')
stripstring2=stripstring2.strip('\}')
stripstring2=stripstring2.strip('\"')
#print("i am in task")
temparr3=temparr[1].split(":")
stripstring3=temparr3[1].strip(' ')
stripstring3=stripstring3.strip('\'')
#print("dynamo date ",stripstring3)
curIdnew=datetime.now().strftime("%Y-%m-%d")
#print("cur date ",curIdnew)
stripstring3=stripstring3.strip('\"')
if stripstring3==datetime.now().strftime("%Y-%m-%d"):
#print("i am fully in")
x.append(stripstring2)
str4=""
if not x:
str4="you do not have any task deadlines today."
else:
str4='the tasks with deadline today are: '
str4=str4+' , '.join(str(e) for e in x)
str3=str3+' '+str4
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': '{}'.format(str3) })
def wikiintentfunc(intent_request):
inputt=get_slots(intent_request)["inputt"]
flagg=0
source = intent_request['invocationSource']