-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (30 loc) · 1.28 KB
/
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
28
29
30
31
32
33
34
35
from flask import Flask, render_template, request, send_file
from geopy.geocoders import Nominatim
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=Nominatim(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)