File size: 1,407 Bytes
447534c 934eb5f 447534c 806b4d5 09ff8b4 c3566a3 447534c | 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 | from flask import Flask, render_template, request
from parser_1 import gmaps_parser
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def display_data():
location = None
country_code = None
error_message = None
all_place_details = []
if request.method == "POST":
location = request.form.get("location")
country_code = request.form.get("country_code")
if location and country_code:
scraped_data = gmaps_parser(location=location, country_code=country_code)
try:
list = scraped_data["scrapingResult"]["locals"]
except KeyError:
error_message = "Error: Data might be unavailable for this location."
else:
error_message = ""
for place in list:
try:
place_details = [place['title'], place['address'], place['website']]
except KeyError:
error_message = "Error: Data might be unavailable for this location."
else:
all_place_details.append(place_details)
all_place_details=all_place_details
return render_template("data.html", location=location, country_code=country_code, all_place_details=all_place_details, error_message=error_message)
if __name__ == "__main__":
app.run(debug=True)
|