Skip to content

Commit bf32241

Browse files
authored
Geo_coder_files
Geo_coder_files
1 parent 2ca7403 commit bf32241

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

Diff for: app_ver4.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from flask import Flask, render_template, request, send_file
2+
from geopy.geocoders import Nominatim
3+
import pandas
4+
import datetime
5+
6+
7+
app=Flask(__name__) # create flask instance...
8+
9+
@app.route("/")
10+
def index():
11+
return render_template("index.html")
12+
13+
@app.route('/success-table', methods=['POST'])
14+
def success_table():
15+
global filename
16+
if request.method == "POST":
17+
file=request.files['file']
18+
try:
19+
df=pandas.read_csv(file)
20+
gc=Nomination()
21+
df["coordinates"]=df["Address"].apply(gc.geocode)
22+
df['Latitude']=df['coordinates'].apply(lambda x: x.latitude if x != None else None)
23+
df['Longitude']=df['coordinates'].apply(lambda x: x.longitude if x != None else None)
24+
df=df.drop("coordinates",1)
25+
filename=datetime.datetime.now().strftime("uploads/%Y-%m-%d-%H-%M-%S-%f"+".csv")
26+
df.to_csv(filename,index=None)
27+
return render_template("index.html", text=df.to_html(), btn='download.html')
28+
except:
29+
return render_template("index.html", text="Please make sure you have an address column in your csv file!")
30+
31+
@app.route("/download-file/")
32+
def download():
33+
return send_file("uploads/geocoded.csv", attachment_filename='yourfile.csv', as_attachment=True)
34+
35+
if __name__=="__main__":
36+
app.run(debug=True)

Diff for: download.html

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<div class="download">
4+
<a href={{url_for('download')}} target="blank"> <button class="btn"> Download </button></a>
5+
</div>
6+
</html>

Diff for: index.html

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
<!DOCTYPE html>
2-
<!-- Martin Batista - Python Developer -->
32
<html lang="en">
4-
<title>Data Collector App</title>
5-
<head>
6-
<link href="../static/main.css" rel="stylesheet">
7-
</head>
8-
<body>
9-
10-
<div class="container">
11-
<h1>Collecting Height</h1>
12-
<h3>Please fill the entrees to get population statistics on Height</h3>
13-
<div class="message">
14-
{{text | safe}}
15-
</div>
16-
<form action="{{url_for('success')}}" method="POST">
17-
<input title="Your email will be safe with us" placeholder="Enter your email address" type="email" name="email_name" required><br>
18-
<input title="Your data will be safe with us" placeholder="Enter your height in cm" type="number" min="50", max="300" step="0.1" name="height_name" required><br>
19-
<button type-"submit"> Submit </button>
20-
</form>
21-
</div>
22-
</body>
3+
<title> Super Geocoder </title>
4+
<head>
5+
<link href="../static/main.css" rel="stylesheet">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<h1>Super Geocoder</h1>
10+
<h3>Please upload your csv file. the values containing addressess should be in a column named <em>addresses</em> or <em>address</em></h3>
11+
<form action="{{url_for('success_table')}}" method="POST" enctype="multipart/form-data">
12+
<input type="file" accept=".csv" name="file" />
13+
<button type="submit"> Submit </button>
14+
</form>
15+
<div class="output">
16+
{{text|safe}}
17+
{% include btn ignore missing %}
18+
</div>
19+
<div>
20+
</body>
2321
</html>

0 commit comments

Comments
 (0)