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
| app = Flask(__name__)
google_api_key = os.environ.get('GM_API_KEY')
parser = Parser(STOP_WORDS)
gmap = GMaps(google_api_key)
wiki = Wiki()
@app.route('/_get_json')
def get_json():
user_input = request.args.get( "question", type=str)
parsed_input = parser.get_relevant_words(user_input)
if parsed_input == "":
failure_msg = return_failure()
return jsonify(message1=failure_msg,
error=True)
gmap_place = gmap.get_position(parsed_input)
if gmap_place != "no result":
wiki_result = wiki.get_wiki_result(
gmap_place["latitude"], gmap_place["longitude"], parsed_input)
msg_adress = return_address(gmap_place["address"])
if wiki_result != "no result":
msg_summary = return_story(wiki_result['summary'])
return jsonify(lat=gmap_place["latitude"],
lng=gmap_place["longitude"],
message1=msg_adress,
message2=msg_summary,
url=wiki_result["url"],
error=False)
failure_msg = return_failure()
return jsonify(message1=failure_msg,
error=True)
failure_msg = return_failure()
return jsonify(message1=failure_msg,
error=True)
@app.route('/')
@app.route('/home_page')
def index():
return render_template('home_page.html', api_key=google_api_key)
if __name__ == "__main__":
app.run(debug=True) |