-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikipedia.py
42 lines (32 loc) · 1.07 KB
/
wikipedia.py
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
import wikipediaapi
from speaker import Speaker
speaker = Speaker()
def isQuestion(userCommand):
arr = ["who","when","what","where","how"]
for element in arr :
if element in userCommand.lower():
return True
return False
class Wikipedia :
def __init__(self,userCommand):
self.command = userCommand
self.keyword = ""
self.summary = ""
def findKeyword(self):
arr,commandSplitted= ["is","are","was","were"],self.command.split()
for i,element in enumerate(commandSplitted):
if(element in arr):
i+=1
while(i<len(commandSplitted)):
self.keyword+=(commandSplitted[i]+" ")
i+=1
def doesPageExist(self):
if(self.keyword==""):
return False
page_py = wikipediaapi.Wikipedia('en').page(self.keyword)
if(not page_py.exists()):
return False
self.summary = (page_py.summary)
return True
def displaySummary(self):
speaker.printAndSpeak(self.summary)