-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathknowledged.py
More file actions
executable file
·50 lines (40 loc) · 1.2 KB
/
knowledged.py
File metadata and controls
executable file
·50 lines (40 loc) · 1.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
# -*- coding: utf-8-*-
import random
import re
import wolframalpha
import time
import sys
from sys import maxint
from client import jasperpath
WORDS = ["WHO", "WHAT", "HOW MUCH", "HOW MANY", "HOW OLD"]
PRIORITY = 3
def handle(text, mic, profile):
messages = ["Searching Online databases","Let me google that for you"]
message = random.choice(messages)
mic.say(message)
app_id = profile['keys']['WOLFRAMALPHA']
client = wolframalpha.Client(app_id)
query = client.query(text)
if len(query.pods) > 0:
texts = ""
pod = query.pods[1]
if pod.text:
texts = pod.text
else:
texts = "I can not find anything"
mic.say(texts.replace("|",""))
else:
mic.say("Sorry, Could you be more specific?.")
def isValid(text):
if re.search(r'\bwho\b', text, re.IGNORECASE):
return True
elif re.search(r'\bwhat\b', text, re.IGNORECASE):
return True
elif re.search(r'\bhow much\b', text, re.IGNORECASE):
return True
elif re.search(r'\bhow MANY\b', text, re.IGNORECASE):
return True
elif re.search(r'\bhow old\b', text, re.IGNORECASE):
return True
else:
return False