Skip to content

Commit 03e1e13

Browse files
committed
Added 10th Project
1 parent 2ed6b90 commit 03e1e13

19 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# geocoder-web-service
2+
Geocoder Web Service made in Flask .Upload Documents only if it has Address Column.
331 Bytes
Binary file not shown.
Binary file not shown.
295 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from flask import Flask, render_template, request, send_file
2+
from geopy.geocoders import Nominatim
3+
import pandas
4+
import datetime
5+
6+
app=Flask(__name__)
7+
8+
@app.route("/")
9+
def index():
10+
return render_template("index.html")
11+
12+
@app.route('/success-table', methods=['POST'])
13+
def success_table():
14+
global filename
15+
if request.method=="POST":
16+
file=request.files['file']
17+
try:
18+
df=pandas.read_csv(file)
19+
gc=Nominatim(scheme='http')
20+
df["coordinates"]=df["Address"].apply(gc.geocode)
21+
df['Latitude'] = df['coordinates'].apply(lambda x: x.latitude if x != None else None)
22+
df['Longitude'] = df['coordinates'].apply(lambda x: x.longitude if x != None else None)
23+
df=df.drop("coordinates",1)
24+
filename=datetime.datetime.now().strftime("sample_files/%Y-%m-%d-%H-%M-%S-%f"+".csv")
25+
df.to_csv(filename,index=None)
26+
return render_template("index.html", text=df.to_html(), btn='download.html')
27+
except Exception as e:
28+
return render_template("index.html", text=str(e))
29+
30+
@app.route("/download-file/")
31+
def download():
32+
return send_file(filename, attachment_filename='yourfile.csv', as_attachment=True)
33+
34+
if __name__=="__main__":
35+
app.run(debug=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ID,Address,Name,Employees,Latitude,Longitude
2+
1, 3666 21st St San Francisco CA 94114 USA, Madeira,8,37.756488877551,-122.429343346939
3+
2, 735 Dolores St San Francisco CA 94119 USA, Bready Shop,15,,
4+
3, 332 Hill St San Francisco California 94114 USA, Super River,25,37.755725122449,-122.428601306122
5+
4, 3995 23rd St San Francisco CA 94114 USA, Ben's Shop,10,37.7529648,-122.431714
6+
5,1056 Sanchez St San Francisco California USA,Sanchez,12,37.7521458,-122.42981516
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ID,Address,Name,Employees,Latitude,Longitude
2+
1, 3666 21st St San Francisco CA 94114 USA, Madeira,8,37.756488877551,-122.429343346939
3+
2, 735 Dolores St San Francisco CA 94119 USA, Bready Shop,15,,
4+
3, 332 Hill St San Francisco California 94114 USA, Super River,25,37.755725122449,-122.428601306122
5+
4, 3995 23rd St San Francisco CA 94114 USA, Ben's Shop,10,37.7529648,-122.431714
6+
5,1056 Sanchez St San Francisco California USA,Sanchez,12,37.7521458,-122.42981516
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ID,Address,Name,Employees,Latitude,Longitude
2+
1, 3666 21st St San Francisco CA 94114 USA, Madeira,8,,
3+
2, 735 Dolores St San Francisco CA 94119 USA, Bready Shop,15,,
4+
3, 332 Hill St San Francisco California 94114 USA, Super River,25,37.755725122449,-122.428601306122
5+
4, 3995 23rd St San Francisco CA 94114 USA, Ben's Shop,10,,
6+
5,1056 Sanchez St San Francisco California USA,Sanchez,12,37.7521458,-122.42981516
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ID,Address,Name,Employees,Latitude,Longitude
2+
1, 3666 21st St San Francisco CA 94114 USA, Madeira,8,37.756488877551,-122.429343346939
3+
2, 735 Dolores St San Francisco CA 94119 USA, Bready Shop,15,,
4+
3, 332 Hill St San Francisco California 94114 USA, Super River,25,37.755725122449,-122.428601306122
5+
4, 3995 23rd St San Francisco CA 94114 USA, Ben's Shop,10,37.7529648,-122.4317141
6+
5,1056 Sanchez St San Francisco California USA,Sanchez,12,37.7521458,-122.42981516
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ID,Address,Name,Employees,Latitude,Longitude
2+
1, 3666 21st St San Francisco CA 94114 USA, Madeira,8,37.756488877551,-122.429343346939
3+
2, 735 Dolores St San Francisco CA 94119 USA, Bready Shop,15,,
4+
3, 332 Hill St San Francisco California 94114 USA, Super River,25,37.755725122449,-122.428601306122
5+
4, 3995 23rd St San Francisco CA 94114 USA, Ben's Shop,10,37.7529648,-122.4317141
6+
5,1056 Sanchez St San Francisco California USA,Sanchez,12,37.7521458,-122.42981516
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
html, body {
2+
height: 100%;
3+
margin: 0;
4+
}
5+
6+
.container {
7+
margin: 0 auto;
8+
width: 100%;
9+
height: 100%;
10+
background-color: #006666;
11+
color: #e6ffff;
12+
overflow:hidden;
13+
text-align: center;
14+
}
15+
16+
.container form {
17+
margin: 20px;
18+
}
19+
20+
.container h1 {
21+
font-family: Arial, sans-serif;
22+
font-size: 30px;
23+
color: #DDCCEE;
24+
margin-top: 80px;
25+
}
26+
27+
.container button {
28+
width:70px;
29+
height: 30px;
30+
background-color: steelblue;
31+
margin: 3px;
32+
}
33+
34+
.container input {
35+
width: 200px;
36+
height: 15px;
37+
font-size: 15px;
38+
margin: 2px;
39+
padding: 5px;
40+
transition: all 0.2s ease-in-out;
41+
}
42+
43+
.output {
44+
display: inline-block;
45+
}
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
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 addresses should be in a column named <em>address</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>
21+
</html>

0 commit comments

Comments
 (0)