-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
27 lines (23 loc) · 777 Bytes
/
app.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
from flask import Flask, request, render_template
from twilio.twiml.messaging_response import MessagingResponse
import wikipediaapi
wiki_wiki = wikipediaapi.Wikipedia('en')
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/whatsapp", methods=["POST"])
def reply_whatsapp():
#fetch msg
msg = request.form.get("Body")
#create reply
response = MessagingResponse()
page_py = wiki_wiki.page(msg) #get data from wikipedia
res="No result found for:'"+msg+"'"
if page_py.exists():
res=str(page_py.title)+"\n"+str(page_py.summary[0:500])+"...\nfor more visit:"+str(page_py.fullurl)
#send reply
response.message(res)
return str(response)
if __name__ == "__main__":
app.run()