From 9b8f8f47e4fa77c4f840ff75e65fadbd13b5dece Mon Sep 17 00:00:00 2001 From: sugarlust Date: Sat, 23 Jul 2022 23:03:02 +0530 Subject: [PATCH] initial commit --- app.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..170f846 --- /dev/null +++ b/app.py @@ -0,0 +1,35 @@ +from flask import Flask, render_template, request, send_file +from geopy.geocoders import ArcGIS +import pandas +import datetime + +app=Flask(__name__) + +@app.route("/") +def index(): + return render_template("index.html") + +@app.route('/success-table', methods=['POST']) +def success_table(): + global filename + if request.method=="POST": + file=request.files['file'] + try: + df=pandas.read_csv(file) + gc=ArcGIS(scheme='http') + df["coordinates"]=df["Address"].apply(gc.geocode) + df['Latitude'] = df['coordinates'].apply(lambda x: x.latitude if x != None else None) + df['Longitude'] = df['coordinates'].apply(lambda x: x.longitude if x != None else None) + df=df.drop("coordinates",1) + filename=datetime.datetime.now().strftime("sample_files/%Y-%m-%d-%H-%M-%S-%f"+".csv") + df.to_csv(filename,index=None) + return render_template("index.html", text=df.to_html(), btn='download.html') + except Exception as e: + return render_template("index.html", text=str(e)) + +@app.route("/download-file/") +def download(): + return send_file(filename, attachment_filename='yourfile.csv', as_attachment=True) + +if __name__=="__main__": + app.run(debug=True)