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 52 53 54 55 56 57 58 59
| import wikipedia
import requests
import json
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route("/retrieve")
def retrieve():
return render_template('/grandPy.html')
@app.route("/data", methods=['POST'])
def get_data_api():
get_data_for_js = app_grand_py.get_data(request.form['text'])
return get_data_for_js
class getData:
def __init__(self):
self.data = ""
self.latitude = ""
self.longitude = ""
def get_data(self, city):
city_list = ["paris", "marseille", "lyon", "toulouse", "nice", "nantes", "montpellier", "strasbourg", "bordeaux", "lille", "rennes", "reims", "toulon",
"grenoble", "dijon", "angers", "nimes", "villeurbanne", "limoges", "annecy", "perpignan", "metz", "argenteuil", "rouen", "mulhouse",
"montreuil", "caen", "nancy", "tourcoing", "roubaix", "nanterre", "avignon", "dunkerque", "poitiers"]
self.data = ""
for i in range(len(city.split())):
for j in range(len(city_list)):
if city.split()[i] == city_list[j]:
self.data = city.split()[i]
if self.data == "":
response = "Désolé je ne sais pas du tout !"
return jsonify({"wiki_answer": response})
else:
wiki = wikipedia.set_lang("fr")
data_wiki = wikipedia.summary(self.data, sentences=2)
url = requests.get("https://maps.googleapis.com/maps/api/geocode/json?address="+self.data+"&key=MYKEY")
url = json.loads(url.text)
location = url['results'][0]['geometry']['location']
lat = location['lat']
lng = location['lng']
return jsonify({"wiki_answer": data_wiki}, {"data_lat": lat}, {"data_lng": lng})
if __name__ == "__main__":
app_grand_py = getData()
app.run(debug=True) |