-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9b8f8f4
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |