From 8b224a3808bb2f11eb8be1bbf3bb04cbb2fa9440 Mon Sep 17 00:00:00 2001 From: cTatu Date: Tue, 17 Dec 2019 12:12:05 +0100 Subject: [PATCH 1/7] docker web server --- Dockerfile | 11 ++++++++++ README.md | 8 ++++++++ web.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 Dockerfile create mode 100644 web.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..54363eb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.7-buster + +ENV APP_HOME /home +WORKDIR $APP_HOME +COPY . . + +RUN pip install -r requirements.txt +RUN pip install flask +RUN pip install werkzeug + +CMD python web.py \ No newline at end of file diff --git a/README.md b/README.md index 48ba805..af2fd65 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ This is a script that generates an interactive geo heatmap from your Google loca ## Getting Started +### Using docker web-server +`docker build -t geo_heatmap_web . && docker run -d -p 80:80 geo_heatmap_web` + +Open browser on `http://localhost` +___ + +### Or runing from source + ### 1. Install Python 3+ If you don't already have Python 3+ installed, grab it from . You'll want to download install the latest version of **Python 3.x**. As of 2019-11-22, that is Version 3.8. diff --git a/web.py b/web.py new file mode 100644 index 0000000..bd9be4f --- /dev/null +++ b/web.py @@ -0,0 +1,59 @@ +import os +from flask import Flask, flash, request, redirect, url_for, send_from_directory, current_app +from werkzeug.utils import secure_filename +from geo_heatmap import Generator + +UPLOAD_FOLDER = '/home/' +ALLOWED_EXTENSIONS = {'zip', 'json', 'kml'} + +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +def allowed_file(filename): + return '.' in filename and \ + filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + +@app.route('/uploads/') +def download(filename): + uploads = os.path.join(current_app.root_path, '') + return send_from_directory(directory=uploads, filename=filename, as_attachment=True) + +@app.route('/', methods=['GET', 'POST']) +def upload_file(): + if request.method == 'POST': + # check if the post request has the file part + if 'file' not in request.files: + flash('No file part') + return redirect(request.url) + file = request.files['file'] + # if user does not select file, browser also + # submit an empty part without filename + if file.filename == '': + flash('No selected file') + return redirect(request.url) + if file and allowed_file(file.filename): + filename = secure_filename(file.filename) + path_save = os.path.join(app.config['UPLOAD_FOLDER'], filename) + path_out = os.path.join(app.config['UPLOAD_FOLDER'], os.path.splitext(filename)[0]+'.html') + file.save(path_save) + + generator = Generator() + generator.run([filename], path_out, [None, None], True, 'OpenStreetMap') + + os.remove(path_save) + + return redirect(url_for('download', + filename=path_out.split('/')[-1])) + return ''' + + Geo Heatmap Generator +

Geo Heatmap Generator

+

Upload zip file from Google Maps History

+
+ + +
+ ''' + +if __name__ == "__main__": + app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 80))) \ No newline at end of file From d68eb9e8f03c0d9ec24ed6ed8ab1e40d868f63fe Mon Sep 17 00:00:00 2001 From: cTatu Date: Tue, 17 Dec 2019 21:39:05 +0100 Subject: [PATCH 2/7] reviews added --- .dockerignore | 2 ++ Dockerfile | 6 +++--- README.md | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c84bae6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +Dockerfile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 54363eb..9db9ba8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,8 @@ ENV APP_HOME /home WORKDIR $APP_HOME COPY . . -RUN pip install -r requirements.txt -RUN pip install flask -RUN pip install werkzeug +RUN pip install -r requirements.txt \ + && pip install flask \ + && pip install werkzeug CMD python web.py \ No newline at end of file diff --git a/README.md b/README.md index af2fd65..1eafe21 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,14 @@ This is a script that generates an interactive geo heatmap from your Google loca ## Getting Started ### Using docker web-server -`docker build -t geo_heatmap_web . && docker run -d -p 80:80 geo_heatmap_web` +```shell +docker build -t geo_heatmap_web . +docker run -d -p 80:80 geo_heatmap_web +``` Open browser on `http://localhost` ___ -### Or runing from source - ### 1. Install Python 3+ If you don't already have Python 3+ installed, grab it from . You'll want to download install the latest version of **Python 3.x**. As of 2019-11-22, that is Version 3.8. From 16a3796b2f63fbbc34ce5bdfec3e90912533f02d Mon Sep 17 00:00:00 2001 From: ctatu Date: Mon, 10 Feb 2020 17:01:04 +0100 Subject: [PATCH 3/7] use render_template --- web.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/web.py b/web.py index bd9be4f..efc6311 100644 --- a/web.py +++ b/web.py @@ -1,5 +1,5 @@ import os -from flask import Flask, flash, request, redirect, url_for, send_from_directory, current_app +from flask import Flask, flash, request, redirect, url_for, send_from_directory, current_app, render_template from werkzeug.utils import secure_filename from geo_heatmap import Generator @@ -44,16 +44,7 @@ def upload_file(): return redirect(url_for('download', filename=path_out.split('/')[-1])) - return ''' - - Geo Heatmap Generator -

Geo Heatmap Generator

-

Upload zip file from Google Maps History

-
- - -
- ''' + return render_template('index.html') if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 80))) \ No newline at end of file From 69803e6978d820f029c1215dbf1a40db1a71cd56 Mon Sep 17 00:00:00 2001 From: ctatu Date: Mon, 10 Feb 2020 17:10:59 +0100 Subject: [PATCH 4/7] explication commands --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1eafe21..5e9eac8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,11 @@ docker build -t geo_heatmap_web . docker run -d -p 80:80 geo_heatmap_web ``` -Open browser on `http://localhost` +`build` command creates a docker `image` from the `Dockerfile` and saves it with name pointed by paramter `-t`. +`run` command create a new instance of the previews created image and starts it. `-p` parameter is used to public and map +the host ports with the container ports. + +Now open browser on `http://localhost` ___ ### 1. Install Python 3+ From d0d72e65433b6bb9660f009954596f25922af962 Mon Sep 17 00:00:00 2001 From: ctatu Date: Mon, 10 Feb 2020 17:13:00 +0100 Subject: [PATCH 5/7] separation --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5e9eac8..23265de 100644 --- a/README.md +++ b/README.md @@ -12,29 +12,31 @@ docker build -t geo_heatmap_web . docker run -d -p 80:80 geo_heatmap_web ``` -`build` command creates a docker `image` from the `Dockerfile` and saves it with name pointed by paramter `-t`. +`build` command creates a docker `image` from the `Dockerfile` and saves it with name pointed by paramter `-t`. + `run` command create a new instance of the previews created image and starts it. `-p` parameter is used to public and map the host ports with the container ports. Now open browser on `http://localhost` ___ +### Run the script natively -### 1. Install Python 3+ +#### 1. Install Python 3+ If you don't already have Python 3+ installed, grab it from . You'll want to download install the latest version of **Python 3.x**. As of 2019-11-22, that is Version 3.8. -### 2. Get Your Location Data +#### 2. Get Your Location Data Here you can find out how to download your Google data:
Here you can download all of the data that Google has stored on you: To use this script, you only need to select and download your "Location History", which Google will provide to you as a JSON file by default. KML is also an output option and is accepted for this program. -### 3. Clone This Repository +#### 3. Clone This Repository On , click the green "Clone or Download" button at the top right of the page. If you want to get started with this script more quickly, click the "Download ZIP" button, and extract the ZIP somewhere on your computer. -### 4. Install Dependencies +#### 4. Install Dependencies In a [command prompt or Terminal window](https://tutorial.djangogirls.org/en/intro_to_command_line/#what-is-the-command-line), [navigate to the directory](https://tutorial.djangogirls.org/en/intro_to_command_line/#change-current-directory) containing this repository's files. Then, type the following, and press enter: @@ -42,7 +44,7 @@ In a [command prompt or Terminal window](https://tutorial.djangogirls.org/en/int pip install -r requirements.txt ``` -### 5. Run the Script +#### 5. Run the Script In the same command prompt or Terminal window, type the following, and press enter: From d679ca0f3098db8a9443e5185fd4c5db4700e3d1 Mon Sep 17 00:00:00 2001 From: Cristian Tatu Date: Thu, 13 Feb 2020 12:51:53 +0100 Subject: [PATCH 6/7] Create index.html --- index.html | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..6fb8ad2 --- /dev/null +++ b/index.html @@ -0,0 +1,8 @@ + +Geo Heatmap Generator +

Geo Heatmap Generator

+

Upload zip file from Google Maps History

+
+ + +
From 58e971761d8eff1957b78b3bc3b18721b3149067 Mon Sep 17 00:00:00 2001 From: Cristian Tatu Date: Thu, 13 Feb 2020 12:53:48 +0100 Subject: [PATCH 7/7] move to templates folder --- index.html => templates/index.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename index.html => templates/index.html (100%) diff --git a/index.html b/templates/index.html similarity index 100% rename from index.html rename to templates/index.html