Upload getvalues.py
Browse files- getvalues.py +103 -0
getvalues.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
# from listen import *
|
3 |
+
|
4 |
+
# find time in the string input provided by the user
|
5 |
+
def findTime(input):
|
6 |
+
# time = re.search(r'\d{1,2}:\d{2}', input)
|
7 |
+
# meridiem = re.search(r'\b(am|pm)\b', input)
|
8 |
+
# if time:
|
9 |
+
# tvalue = f"{time.group()} {meridiem.group()}"
|
10 |
+
# return tvalue
|
11 |
+
# else:
|
12 |
+
# return "notime"
|
13 |
+
time_regex1 = r"(1[0-2]|[1-9]):[0-5][0-9] (am|AM|PM|pm)"
|
14 |
+
time_search = re.search(time_regex1, input)
|
15 |
+
if time_search:
|
16 |
+
time = time_search.group(0)
|
17 |
+
# meridian = time_search.group(2)
|
18 |
+
return time
|
19 |
+
else:
|
20 |
+
time_regex2 = r"(1[0-2]|[1-9])\s?(am|AM|pm|PM)"
|
21 |
+
time_search = re.search(time_regex2, input)
|
22 |
+
if time_search:
|
23 |
+
time = time_search.group(0)
|
24 |
+
# meridian = time_search.group(2)
|
25 |
+
return time
|
26 |
+
else:
|
27 |
+
return "notime"
|
28 |
+
|
29 |
+
# find number in the string input provided by the user
|
30 |
+
def findNumber(input):
|
31 |
+
number = re.search(r'\d+(?:st|nd|rd|th)', input)
|
32 |
+
if number:
|
33 |
+
return number.group()
|
34 |
+
else:
|
35 |
+
return "nonum"
|
36 |
+
|
37 |
+
# # find date in the string input provided by the user
|
38 |
+
def findDate(input):
|
39 |
+
date = re.search(r'\d{1,2}/\d{1,2}/\d{4}', input)
|
40 |
+
if date:
|
41 |
+
return date.group()
|
42 |
+
else:
|
43 |
+
return "nodate"
|
44 |
+
|
45 |
+
# find month in the string input provided by the user
|
46 |
+
def findMonth(input):
|
47 |
+
month = re.search(r'\b(january|february|march|april|may|june|july|august|september|october|november|december|next month)\b', input)
|
48 |
+
if month:
|
49 |
+
return month.group()
|
50 |
+
else:
|
51 |
+
return "nomonth"
|
52 |
+
|
53 |
+
# find day in the string input provided by the user
|
54 |
+
def findDay(input):
|
55 |
+
day = re.search(r'\b(monday|tuesday|wednesday|thursday|friday|saturday|sunday|tomorrow|day after tomorrow|this week|next week|today)\b', input)
|
56 |
+
if day:
|
57 |
+
return day.group()
|
58 |
+
else:
|
59 |
+
return "noday"
|
60 |
+
|
61 |
+
def findrepeat(input):
|
62 |
+
repeat = re.search(r'\b(daily|everyday|every week|every month|every sunday|every monday|every tuesday|every wednesday|every thursday|every friday|every saturday)\b', input)
|
63 |
+
if repeat:
|
64 |
+
return repeat.group()
|
65 |
+
else:
|
66 |
+
return "norepeat"
|
67 |
+
|
68 |
+
|
69 |
+
def getValues(query):
|
70 |
+
time = findTime(query)
|
71 |
+
num = findNumber(query)
|
72 |
+
reps = findrepeat(query)
|
73 |
+
date = findDate(query)
|
74 |
+
month = findMonth(query)
|
75 |
+
day = findDay(query)
|
76 |
+
message = query.lower().replace(time, "").replace(day, "").replace(reps, "").replace("create a reminder", "").replace("remind me to", "").replace("cosmo", ""). replace("remind", "")
|
77 |
+
values = {"message": message,
|
78 |
+
"time": time,
|
79 |
+
"day": day,
|
80 |
+
"date": date,
|
81 |
+
"reps": reps,
|
82 |
+
"num": num,
|
83 |
+
"month": month
|
84 |
+
}
|
85 |
+
return values
|
86 |
+
|
87 |
+
# query = "remind me to work on my portfolio at 5:00 pm tomorrow"
|
88 |
+
# print(getValues(query))
|
89 |
+
|
90 |
+
# query = input("Enter your query : ")
|
91 |
+
# # time = findTime(query)
|
92 |
+
# # date = findDate(query)
|
93 |
+
# # day = findDay(query)
|
94 |
+
# # if day == "noday":
|
95 |
+
# # print("No day")
|
96 |
+
# # elif time == "notime":
|
97 |
+
# # print("Time not found")
|
98 |
+
# # else:
|
99 |
+
# # print("Time found")
|
100 |
+
|
101 |
+
|
102 |
+
# # query = MicExecution()
|
103 |
+
# print(findDay(query))
|