From 98c4631d3dec0f86d4c2bbecce06a71b5a8d2da3 Mon Sep 17 00:00:00 2001 From: Najipian Date: Thu, 15 Nov 2018 18:14:48 +0200 Subject: [PATCH 01/16] show logged user in home template --- app/modules/home.html | 1 + app/modules/home.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/modules/home.html b/app/modules/home.html index b8554a0..7f6d4c7 100644 --- a/app/modules/home.html +++ b/app/modules/home.html @@ -9,5 +9,6 @@

Home

  • Datastore example (load)
  • Yaml example
  • +

    Loged in as : {{user_name}}

    diff --git a/app/modules/home.py b/app/modules/home.py index 8850ae3..9521d49 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -2,9 +2,11 @@ import logging import os from google.appengine.ext.webapp import template +from google.appengine.api import users class HomeHandler(webapp2.RequestHandler): def get(self): logging.info("HomeHandler get()") + user = users.get_current_user() template_path = os.path.join(os.path.dirname(__file__), 'home.html') - self.response.write(template.render(template_path, {})) + self.response.write(template.render(template_path, {'user_name' : user.nickname()})) From 7087c1b7255f37514d5fdf4d6ca4926183bd425e Mon Sep 17 00:00:00 2001 From: Najipian Date: Thu, 15 Nov 2018 18:42:36 +0200 Subject: [PATCH 02/16] miss spelling corrected --- app/modules/home.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/home.html b/app/modules/home.html index 7f6d4c7..da8027f 100644 --- a/app/modules/home.html +++ b/app/modules/home.html @@ -9,6 +9,6 @@

    Home

  • Datastore example (load)
  • Yaml example
  • -

    Loged in as : {{user_name}}

    +

    Logged in as : {{user_name}}

    From bb196187da339a73311ad5b6d24eb9fd15345206 Mon Sep 17 00:00:00 2001 From: Najipian Date: Sun, 18 Nov 2018 14:25:54 +0200 Subject: [PATCH 03/16] twice square ta=raining task --- .datastore/.gitkeep | 0 .env.dist | 0 .gitignore | 1 + README.md | 0 TASKS.md | 0 app-deploy.yaml | 0 app.yaml | 0 app/__init__.py | 0 app/handlers.py | 2 ++ app/modules/__init__.py | 0 app/modules/common/__init__.py | 1 + app/modules/common/squares.py | 23 ++++++++++++++++++ app/modules/examples/__init__.py | 0 app/modules/examples/datastore_example.html | 0 app/modules/examples/datastore_example.py | 0 app/modules/examples/http_example.html | 0 app/modules/examples/http_example.py | 0 app/modules/examples/pipeline_example.html | 0 app/modules/examples/pipeline_example.py | 0 app/modules/examples/yaml_example.html | 0 app/modules/examples/yaml_example.py | 0 app/modules/examples/yaml_example.yaml | 0 app/modules/home.html | 1 + app/modules/home.py | 0 app/modules/training/__init__.py | 1 + app/modules/training/pipeline_training.py | 27 +++++++++++++++++++++ app/modules/training/pipeline_traning.html | 8 ++++++ docker-compose.yml | 0 docker/Dockerfile | 0 env.yaml.dist | 0 index.yaml | 0 libs/.gitkeep | 0 main.py | 0 requirements.txt | 0 34 files changed, 64 insertions(+) mode change 100644 => 100755 .datastore/.gitkeep mode change 100644 => 100755 .env.dist mode change 100644 => 100755 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 TASKS.md mode change 100644 => 100755 app-deploy.yaml mode change 100644 => 100755 app.yaml mode change 100644 => 100755 app/__init__.py mode change 100644 => 100755 app/handlers.py mode change 100644 => 100755 app/modules/__init__.py create mode 100755 app/modules/common/__init__.py create mode 100755 app/modules/common/squares.py mode change 100644 => 100755 app/modules/examples/__init__.py mode change 100644 => 100755 app/modules/examples/datastore_example.html mode change 100644 => 100755 app/modules/examples/datastore_example.py mode change 100644 => 100755 app/modules/examples/http_example.html mode change 100644 => 100755 app/modules/examples/http_example.py mode change 100644 => 100755 app/modules/examples/pipeline_example.html mode change 100644 => 100755 app/modules/examples/pipeline_example.py mode change 100644 => 100755 app/modules/examples/yaml_example.html mode change 100644 => 100755 app/modules/examples/yaml_example.py mode change 100644 => 100755 app/modules/examples/yaml_example.yaml mode change 100644 => 100755 app/modules/home.html mode change 100644 => 100755 app/modules/home.py create mode 100755 app/modules/training/__init__.py create mode 100755 app/modules/training/pipeline_training.py create mode 100755 app/modules/training/pipeline_traning.html mode change 100644 => 100755 docker-compose.yml mode change 100644 => 100755 docker/Dockerfile mode change 100644 => 100755 env.yaml.dist mode change 100644 => 100755 index.yaml mode change 100644 => 100755 libs/.gitkeep mode change 100644 => 100755 main.py mode change 100644 => 100755 requirements.txt diff --git a/.datastore/.gitkeep b/.datastore/.gitkeep old mode 100644 new mode 100755 diff --git a/.env.dist b/.env.dist old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 6cc9a81..dda0959 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Environment vars .env env.yaml +.vscode # Google App Engine files in Docker .datastore/* diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/TASKS.md b/TASKS.md old mode 100644 new mode 100755 diff --git a/app-deploy.yaml b/app-deploy.yaml old mode 100644 new mode 100755 diff --git a/app.yaml b/app.yaml old mode 100644 new mode 100755 diff --git a/app/__init__.py b/app/__init__.py old mode 100644 new mode 100755 diff --git a/app/handlers.py b/app/handlers.py old mode 100644 new mode 100755 index 6c15b7e..82f33ed --- a/app/handlers.py +++ b/app/handlers.py @@ -3,6 +3,7 @@ from app.modules.examples.http_example import HttpExampleHandler from app.modules.examples.datastore_example import DatastoreExampleHandler from app.modules.examples.yaml_example import YamlExampleHandler +from app.modules.training.pipeline_training import PipelineTrainigHandler def handlers(): return [ @@ -15,4 +16,5 @@ def handlers(): (r'/examples/datastore/([^\/]+)', DatastoreExampleHandler), (r'/examples/datastore/([^\/]+)/([^\/]+)', DatastoreExampleHandler), (r'/examples/yaml', YamlExampleHandler), + (r'/training/pipeline/(\d+)', PipelineTrainigHandler), ] diff --git a/app/modules/__init__.py b/app/modules/__init__.py old mode 100644 new mode 100755 diff --git a/app/modules/common/__init__.py b/app/modules/common/__init__.py new file mode 100755 index 0000000..4957e95 --- /dev/null +++ b/app/modules/common/__init__.py @@ -0,0 +1 @@ +# __init__.py needed to create "package" for this directory diff --git a/app/modules/common/squares.py b/app/modules/common/squares.py new file mode 100755 index 0000000..6f8e441 --- /dev/null +++ b/app/modules/common/squares.py @@ -0,0 +1,23 @@ +import webapp2 +import logging +import pipeline + +class SquarePipeline(pipeline.Pipeline): + + def run(self, number): + return number * number + + +class TwiceSquaredPipeline(pipeline.Pipeline): + + def run(self, number): + + first_square = yield SquarePipeline(number) + second_square = yield SquarePipeline(first_square) + yield LogResult(second_square) + + +class LogResult(pipeline.Pipeline): + + def run(self, number): + logging.info('All done! Value is %s', number) \ No newline at end of file diff --git a/app/modules/examples/__init__.py b/app/modules/examples/__init__.py old mode 100644 new mode 100755 diff --git a/app/modules/examples/datastore_example.html b/app/modules/examples/datastore_example.html old mode 100644 new mode 100755 diff --git a/app/modules/examples/datastore_example.py b/app/modules/examples/datastore_example.py old mode 100644 new mode 100755 diff --git a/app/modules/examples/http_example.html b/app/modules/examples/http_example.html old mode 100644 new mode 100755 diff --git a/app/modules/examples/http_example.py b/app/modules/examples/http_example.py old mode 100644 new mode 100755 diff --git a/app/modules/examples/pipeline_example.html b/app/modules/examples/pipeline_example.html old mode 100644 new mode 100755 diff --git a/app/modules/examples/pipeline_example.py b/app/modules/examples/pipeline_example.py old mode 100644 new mode 100755 diff --git a/app/modules/examples/yaml_example.html b/app/modules/examples/yaml_example.html old mode 100644 new mode 100755 diff --git a/app/modules/examples/yaml_example.py b/app/modules/examples/yaml_example.py old mode 100644 new mode 100755 diff --git a/app/modules/examples/yaml_example.yaml b/app/modules/examples/yaml_example.yaml old mode 100644 new mode 100755 diff --git a/app/modules/home.html b/app/modules/home.html old mode 100644 new mode 100755 index da8027f..320464a --- a/app/modules/home.html +++ b/app/modules/home.html @@ -8,6 +8,7 @@

    Home

  • Datastore example (save)
  • Datastore example (load)
  • Yaml example
  • +
  • Pipeline training
  • Logged in as : {{user_name}}

    diff --git a/app/modules/home.py b/app/modules/home.py old mode 100644 new mode 100755 diff --git a/app/modules/training/__init__.py b/app/modules/training/__init__.py new file mode 100755 index 0000000..4957e95 --- /dev/null +++ b/app/modules/training/__init__.py @@ -0,0 +1 @@ +# __init__.py needed to create "package" for this directory diff --git a/app/modules/training/pipeline_training.py b/app/modules/training/pipeline_training.py new file mode 100755 index 0000000..154b244 --- /dev/null +++ b/app/modules/training/pipeline_training.py @@ -0,0 +1,27 @@ +import webapp2 +import logging +import os + +from google.appengine.ext.webapp import template +from app.modules.common.squares import TwiceSquaredPipeline + +class PipelineTrainigHandler(webapp2.RequestHandler): + def get(self, number=10): + logging.info("PipelineTrainigHandler get(%s)" % number) + + if number == "": + number = 10 + else: + number = int(number) + + stage = TwiceSquaredPipeline(number) + stage.start() + + #square_stage = SquarePipeline(number) + #square_stage.start() + + template_path = os.path.join(os.path.dirname(__file__), 'pipeline_traning.html') + self.response.write(template.render(template_path, { + 'number': number, + })) + diff --git a/app/modules/training/pipeline_traning.html b/app/modules/training/pipeline_traning.html new file mode 100755 index 0000000..2e5aa31 --- /dev/null +++ b/app/modules/training/pipeline_traning.html @@ -0,0 +1,8 @@ + + +

    Pipeline Training

    +

    Square a number twice

    +

    Input: {{ number }}

    +

    Check application logs for square output

    + + diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 diff --git a/docker/Dockerfile b/docker/Dockerfile old mode 100644 new mode 100755 diff --git a/env.yaml.dist b/env.yaml.dist old mode 100644 new mode 100755 diff --git a/index.yaml b/index.yaml old mode 100644 new mode 100755 diff --git a/libs/.gitkeep b/libs/.gitkeep old mode 100644 new mode 100755 diff --git a/main.py b/main.py old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 From c968b876b258df1a4010e197bce2d431023cc58c Mon Sep 17 00:00:00 2001 From: Najipian Date: Sun, 18 Nov 2018 19:08:07 +0200 Subject: [PATCH 04/16] http training task --- app.yaml | 4 ++ app/handlers.py | 2 + app/modules/home.html | 1 + app/modules/home.py | 7 +++- app/modules/training/http_training.html | 14 +++++++ app/modules/training/http_training.py | 55 +++++++++++++++++++++++++ requirements.txt | 2 + 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100755 app/modules/training/http_training.html create mode 100644 app/modules/training/http_training.py diff --git a/app.yaml b/app.yaml index 60535e7..e44ed98 100755 --- a/app.yaml +++ b/app.yaml @@ -19,3 +19,7 @@ handlers: includes: - ./env.yaml + +libraries: + - name: ssl + version: 2.7 diff --git a/app/handlers.py b/app/handlers.py index 82f33ed..1747caf 100755 --- a/app/handlers.py +++ b/app/handlers.py @@ -4,6 +4,7 @@ from app.modules.examples.datastore_example import DatastoreExampleHandler from app.modules.examples.yaml_example import YamlExampleHandler from app.modules.training.pipeline_training import PipelineTrainigHandler +from app.modules.training.http_training import HttpTrainingHandler def handlers(): return [ @@ -17,4 +18,5 @@ def handlers(): (r'/examples/datastore/([^\/]+)/([^\/]+)', DatastoreExampleHandler), (r'/examples/yaml', YamlExampleHandler), (r'/training/pipeline/(\d+)', PipelineTrainigHandler), + (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), ] diff --git a/app/modules/home.html b/app/modules/home.html index 320464a..a341e1f 100755 --- a/app/modules/home.html +++ b/app/modules/home.html @@ -9,6 +9,7 @@

    Home

  • Datastore example (load)
  • Yaml example
  • Pipeline training
  • +
  • Http training
  • Logged in as : {{user_name}}

    diff --git a/app/modules/home.py b/app/modules/home.py index 9521d49..d7f5ab3 100755 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -1,12 +1,17 @@ import webapp2 import logging import os +import geocoder from google.appengine.ext.webapp import template from google.appengine.api import users class HomeHandler(webapp2.RequestHandler): def get(self): logging.info("HomeHandler get()") + + # get logind user user = users.get_current_user() + template_path = os.path.join(os.path.dirname(__file__), 'home.html') - self.response.write(template.render(template_path, {'user_name' : user.nickname()})) + + self.response.write(template.render(template_path, {'user_name' : user.nickname() })) diff --git a/app/modules/training/http_training.html b/app/modules/training/http_training.html new file mode 100755 index 0000000..ba916c6 --- /dev/null +++ b/app/modules/training/http_training.html @@ -0,0 +1,14 @@ + + +

    HTTP Training

    + {% if title %} +

    Latitude: {{ lat }}

    +

    Longitude: {{ lon }}

    +

    Title: {{ title }}

    +

    Extract : {{ extract }}

    + + {% else %} +

    {{ error }}

    + {% endif %} + + diff --git a/app/modules/training/http_training.py b/app/modules/training/http_training.py new file mode 100644 index 0000000..a441f2f --- /dev/null +++ b/app/modules/training/http_training.py @@ -0,0 +1,55 @@ +import webapp2 +import logging +import os +import requests +from google.appengine.ext.webapp import template +from requests_toolbelt.adapters import appengine + + +appengine.monkeypatch(validate_certificate=False) + +class HttpTrainingHandler(webapp2.RequestHandler): + def get(self, lat = None, lon = None): + logging.info("HttpTrainingHandler get(%s,%s)" % (lat, lon)) + + # wikipedia base api url + API_HOST = "http://en.wikipedia.org/w/api.php?" + + # add given lat long to api url + apiUrl = "%sformat=json&action=query&prop=extracts&exintro=1&explaintext=1&exlimit=20&generator=geosearch&ggsradius=10000&ggslimit=100&ggscoord=%s%s%s" % (API_HOST, lat,"|", lon) + + logging.info(apiUrl) + + template_vars = {} + + try: + # make the api call + request = requests.get(apiUrl) + data = request.json() + + # check if there is data returned + if 'query' in data : + + for idx , page in data['query']['pages'].items(): + # get the 0 indexd page (first page data) + if page['index'] == 0: + template_vars = { + 'title': page['title'], + 'extract': page['extract'], + } + + break + + else: + # if there is no data returned show user + template_vars = { + 'error' : 'No pages found' + } + except requests.exceptions.RequestException as e: + logging.info(e) + template_vars = { + 'error' : e + } + + template_path = os.path.join(os.path.dirname(__file__), 'http_training.html') + self.response.write(template.render(template_path, template_vars )) diff --git a/requirements.txt b/requirements.txt index 67c8b3a..a3e8c2a 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ GoogleAppEnginePipeline GoogleAppEngineCloudStorageClient requests +requests_toolbelt +geocoder \ No newline at end of file From 86eecde676bd2708b206544a10ae695e6b447b25 Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 19 Nov 2018 13:27:02 +0200 Subject: [PATCH 05/16] correct permissions --- .datastore/.gitkeep | 0 .env.dist | 0 README.md | 0 TASKS.md | 0 app-deploy.yaml | 0 app.yaml | 0 app/__init__.py | 0 app/modules/__init__.py | 0 app/modules/examples/__init__.py | 0 app/modules/examples/datastore_example.html | 0 app/modules/examples/datastore_example.py | 0 app/modules/examples/http_example.html | 0 app/modules/examples/http_example.py | 0 app/modules/examples/pipeline_example.html | 0 app/modules/examples/pipeline_example.py | 0 app/modules/examples/yaml_example.html | 0 app/modules/examples/yaml_example.py | 0 app/modules/examples/yaml_example.yaml | 0 app/modules/home.py | 0 docker-compose.yml | 0 docker/Dockerfile | 0 env.yaml.dist | 0 index.yaml | 0 libs/.gitkeep | 0 main.py | 0 requirements.txt | 0 26 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 .datastore/.gitkeep mode change 100755 => 100644 .env.dist mode change 100755 => 100644 README.md mode change 100755 => 100644 TASKS.md mode change 100755 => 100644 app-deploy.yaml mode change 100755 => 100644 app.yaml mode change 100755 => 100644 app/__init__.py mode change 100755 => 100644 app/modules/__init__.py mode change 100755 => 100644 app/modules/examples/__init__.py mode change 100755 => 100644 app/modules/examples/datastore_example.html mode change 100755 => 100644 app/modules/examples/datastore_example.py mode change 100755 => 100644 app/modules/examples/http_example.html mode change 100755 => 100644 app/modules/examples/http_example.py mode change 100755 => 100644 app/modules/examples/pipeline_example.html mode change 100755 => 100644 app/modules/examples/pipeline_example.py mode change 100755 => 100644 app/modules/examples/yaml_example.html mode change 100755 => 100644 app/modules/examples/yaml_example.py mode change 100755 => 100644 app/modules/examples/yaml_example.yaml mode change 100755 => 100644 app/modules/home.py mode change 100755 => 100644 docker-compose.yml mode change 100755 => 100644 docker/Dockerfile mode change 100755 => 100644 env.yaml.dist mode change 100755 => 100644 index.yaml mode change 100755 => 100644 libs/.gitkeep mode change 100755 => 100644 main.py mode change 100755 => 100644 requirements.txt diff --git a/.datastore/.gitkeep b/.datastore/.gitkeep old mode 100755 new mode 100644 diff --git a/.env.dist b/.env.dist old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/TASKS.md b/TASKS.md old mode 100755 new mode 100644 diff --git a/app-deploy.yaml b/app-deploy.yaml old mode 100755 new mode 100644 diff --git a/app.yaml b/app.yaml old mode 100755 new mode 100644 diff --git a/app/__init__.py b/app/__init__.py old mode 100755 new mode 100644 diff --git a/app/modules/__init__.py b/app/modules/__init__.py old mode 100755 new mode 100644 diff --git a/app/modules/examples/__init__.py b/app/modules/examples/__init__.py old mode 100755 new mode 100644 diff --git a/app/modules/examples/datastore_example.html b/app/modules/examples/datastore_example.html old mode 100755 new mode 100644 diff --git a/app/modules/examples/datastore_example.py b/app/modules/examples/datastore_example.py old mode 100755 new mode 100644 diff --git a/app/modules/examples/http_example.html b/app/modules/examples/http_example.html old mode 100755 new mode 100644 diff --git a/app/modules/examples/http_example.py b/app/modules/examples/http_example.py old mode 100755 new mode 100644 diff --git a/app/modules/examples/pipeline_example.html b/app/modules/examples/pipeline_example.html old mode 100755 new mode 100644 diff --git a/app/modules/examples/pipeline_example.py b/app/modules/examples/pipeline_example.py old mode 100755 new mode 100644 diff --git a/app/modules/examples/yaml_example.html b/app/modules/examples/yaml_example.html old mode 100755 new mode 100644 diff --git a/app/modules/examples/yaml_example.py b/app/modules/examples/yaml_example.py old mode 100755 new mode 100644 diff --git a/app/modules/examples/yaml_example.yaml b/app/modules/examples/yaml_example.yaml old mode 100755 new mode 100644 diff --git a/app/modules/home.py b/app/modules/home.py old mode 100755 new mode 100644 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100755 new mode 100644 diff --git a/docker/Dockerfile b/docker/Dockerfile old mode 100755 new mode 100644 diff --git a/env.yaml.dist b/env.yaml.dist old mode 100755 new mode 100644 diff --git a/index.yaml b/index.yaml old mode 100755 new mode 100644 diff --git a/libs/.gitkeep b/libs/.gitkeep old mode 100755 new mode 100644 diff --git a/main.py b/main.py old mode 100755 new mode 100644 diff --git a/requirements.txt b/requirements.txt old mode 100755 new mode 100644 From f6f4bb24de77bc1afa174ae234d5e0853d9655a5 Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 19 Nov 2018 13:49:03 +0200 Subject: [PATCH 06/16] fix reviews --- .gitignore | 4 +++- app.yaml | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index dda0959..5c14171 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # Environment vars .env env.yaml -.vscode # Google App Engine files in Docker .datastore/* @@ -13,3 +12,6 @@ libs/* # Byte-compiled / optimized / Python files *.pyc + +# vscode folder +.vscode diff --git a/app.yaml b/app.yaml index e44ed98..a2b4548 100644 --- a/app.yaml +++ b/app.yaml @@ -20,6 +20,4 @@ handlers: includes: - ./env.yaml -libraries: - - name: ssl - version: 2.7 + From 32d49ae60948fbc61dc5a705898ee7c785aeaa1a Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 19 Nov 2018 13:50:14 +0200 Subject: [PATCH 07/16] fix reviews --- app/modules/home.py | 2 +- requirements.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/modules/home.py b/app/modules/home.py index d7f5ab3..ac0d5d0 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -1,7 +1,7 @@ import webapp2 import logging import os -import geocoder + from google.appengine.ext.webapp import template from google.appengine.api import users diff --git a/requirements.txt b/requirements.txt index a3e8c2a..d7b2f4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,3 @@ GoogleAppEnginePipeline GoogleAppEngineCloudStorageClient requests requests_toolbelt -geocoder \ No newline at end of file From f844a4b82479491676f255c09dff04e1a0ce3d68 Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 19 Nov 2018 14:00:16 +0200 Subject: [PATCH 08/16] fix reviews --- app/modules/common/squares.py | 13 +++++++++++++ app/modules/examples/pipeline_example.py | 14 ++------------ app/modules/home.py | 2 +- app/modules/training/http_training.html | 3 +-- app/modules/training/http_training.py | 2 +- app/modules/training/pipeline_training.py | 3 --- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/modules/common/squares.py b/app/modules/common/squares.py index 6f8e441..96de852 100755 --- a/app/modules/common/squares.py +++ b/app/modules/common/squares.py @@ -2,6 +2,19 @@ import logging import pipeline +class SquarePipelineExample(pipeline.Pipeline): + + output_names = ['square'] + + def run(self, number): + logging.info("SquarePipelineExample run()") + self.fill(self.outputs.square, number * number) + + def finalized(self): + logging.info("SquarePipelineExample finalized()") + logging.info('All done! Square is %s', self.outputs.square.value) + + class SquarePipeline(pipeline.Pipeline): def run(self, number): diff --git a/app/modules/examples/pipeline_example.py b/app/modules/examples/pipeline_example.py index 7d619e6..2ac3eaf 100644 --- a/app/modules/examples/pipeline_example.py +++ b/app/modules/examples/pipeline_example.py @@ -3,6 +3,7 @@ import os import pipeline from google.appengine.ext.webapp import template +from app.modules.common.squares import SquarePipelineExample class PipelineExampleHandler(webapp2.RequestHandler): def get(self, number=10): @@ -13,7 +14,7 @@ def get(self, number=10): else: number = int(number) - square_stage = SquarePipeline(number) + square_stage = SquarePipelineExample(number) square_stage.start() template_path = os.path.join(os.path.dirname(__file__), 'pipeline_example.html') @@ -21,14 +22,3 @@ def get(self, number=10): 'number': number, })) -class SquarePipeline(pipeline.Pipeline): - - output_names = ['square'] - - def run(self, number): - logging.info("SquarePipeline run()") - self.fill(self.outputs.square, number * number) - - def finalized(self): - logging.info("SquarePipeline finalized()") - logging.info('All done! Square is %s', self.outputs.square.value) diff --git a/app/modules/home.py b/app/modules/home.py index ac0d5d0..99d99cc 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -9,7 +9,7 @@ class HomeHandler(webapp2.RequestHandler): def get(self): logging.info("HomeHandler get()") - # get logind user + # get logiged in user user = users.get_current_user() template_path = os.path.join(os.path.dirname(__file__), 'home.html') diff --git a/app/modules/training/http_training.html b/app/modules/training/http_training.html index ba916c6..0212eb0 100755 --- a/app/modules/training/http_training.html +++ b/app/modules/training/http_training.html @@ -2,8 +2,7 @@

    HTTP Training

    {% if title %} -

    Latitude: {{ lat }}

    -

    Longitude: {{ lon }}

    +

    Title: {{ title }}

    Extract : {{ extract }}

    diff --git a/app/modules/training/http_training.py b/app/modules/training/http_training.py index a441f2f..330b153 100644 --- a/app/modules/training/http_training.py +++ b/app/modules/training/http_training.py @@ -46,7 +46,7 @@ def get(self, lat = None, lon = None): 'error' : 'No pages found' } except requests.exceptions.RequestException as e: - logging.info(e) + logging.error(e) template_vars = { 'error' : e } diff --git a/app/modules/training/pipeline_training.py b/app/modules/training/pipeline_training.py index 154b244..5faef21 100755 --- a/app/modules/training/pipeline_training.py +++ b/app/modules/training/pipeline_training.py @@ -17,9 +17,6 @@ def get(self, number=10): stage = TwiceSquaredPipeline(number) stage.start() - #square_stage = SquarePipeline(number) - #square_stage.start() - template_path = os.path.join(os.path.dirname(__file__), 'pipeline_traning.html') self.response.write(template.render(template_path, { 'number': number, From 37eb5cfb47cdc89142e70e373a3365e446bafcb4 Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 19 Nov 2018 15:46:30 +0200 Subject: [PATCH 09/16] Datastore training --- app/handlers.py | 3 +++ app/modules/common/kinds.py | 7 ++++++ app/modules/home.html | 1 + app/modules/training/datastore_training.html | 11 +++++++++ app/modules/training/datastore_training.py | 24 ++++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 app/modules/common/kinds.py create mode 100644 app/modules/training/datastore_training.html create mode 100644 app/modules/training/datastore_training.py diff --git a/app/handlers.py b/app/handlers.py index 1747caf..2730278 100755 --- a/app/handlers.py +++ b/app/handlers.py @@ -5,6 +5,7 @@ from app.modules.examples.yaml_example import YamlExampleHandler from app.modules.training.pipeline_training import PipelineTrainigHandler from app.modules.training.http_training import HttpTrainingHandler +from app.modules.training.datastore_training import DatastoreTrainingHandler def handlers(): return [ @@ -19,4 +20,6 @@ def handlers(): (r'/examples/yaml', YamlExampleHandler), (r'/training/pipeline/(\d+)', PipelineTrainigHandler), (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), + (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), + (r'/training/datastore', DatastoreTrainingHandler), ] diff --git a/app/modules/common/kinds.py b/app/modules/common/kinds.py new file mode 100644 index 0000000..00c8a0e --- /dev/null +++ b/app/modules/common/kinds.py @@ -0,0 +1,7 @@ +import webapp2 +import logging +from google.appengine.ext import ndb + + +class Example(ndb.Model): + value = ndb.StringProperty() \ No newline at end of file diff --git a/app/modules/home.html b/app/modules/home.html index a341e1f..f363919 100755 --- a/app/modules/home.html +++ b/app/modules/home.html @@ -10,6 +10,7 @@

    Home

  • Yaml example
  • Pipeline training
  • Http training
  • +
  • Datastore training
  • Logged in as : {{user_name}}

    diff --git a/app/modules/training/datastore_training.html b/app/modules/training/datastore_training.html new file mode 100644 index 0000000..597cf8f --- /dev/null +++ b/app/modules/training/datastore_training.html @@ -0,0 +1,11 @@ + + +

    Datastore Training

    +
    + {% for entity in entities %} +

    {{ entity.key }}

    +

    {{ entity.value }}

    + {% endfor %} +
    + + diff --git a/app/modules/training/datastore_training.py b/app/modules/training/datastore_training.py new file mode 100644 index 0000000..1d2001e --- /dev/null +++ b/app/modules/training/datastore_training.py @@ -0,0 +1,24 @@ +import webapp2 +import logging +import os +from google.appengine.ext import ndb +from google.appengine.ext.webapp import template +from app.modules.common.kinds import Example + +class DatastoreTrainingHandler(webapp2.RequestHandler): + def get(self): + logging.info("DatastoreTrainingHandler") + + # get entities + entities_for_example_kind = Example.query().fetch(20) + + # make a list of key value pairs + entities = [] + for entity in entities_for_example_kind: + entities.append({'key':entity.key.string_id() , 'value':entity.value}) + + template_path = os.path.join(os.path.dirname(__file__), 'datastore_training.html') + self.response.write(template.render(template_path, { + 'entities': entities, + })) + From aafb4307f852adc9ff7fd4930c4068c28b1e6fe4 Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 19 Nov 2018 15:51:50 +0200 Subject: [PATCH 10/16] fix reviews --- app.yaml | 2 -- app/modules/home.py | 2 +- app/modules/training/http_training.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app.yaml b/app.yaml index a2b4548..60535e7 100644 --- a/app.yaml +++ b/app.yaml @@ -19,5 +19,3 @@ handlers: includes: - ./env.yaml - - diff --git a/app/modules/home.py b/app/modules/home.py index 99d99cc..3c1e726 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -9,7 +9,7 @@ class HomeHandler(webapp2.RequestHandler): def get(self): logging.info("HomeHandler get()") - # get logiged in user + # get logged in user user = users.get_current_user() template_path = os.path.join(os.path.dirname(__file__), 'home.html') diff --git a/app/modules/training/http_training.py b/app/modules/training/http_training.py index 330b153..e6bf0d2 100644 --- a/app/modules/training/http_training.py +++ b/app/modules/training/http_training.py @@ -5,7 +5,7 @@ from google.appengine.ext.webapp import template from requests_toolbelt.adapters import appengine - +# https://toolbelt.readthedocs.io/en/latest/adapters.html#appengineadapter appengine.monkeypatch(validate_certificate=False) class HttpTrainingHandler(webapp2.RequestHandler): From 730a70c20a4621b462e3d54af4130548e0ef7ade Mon Sep 17 00:00:00 2001 From: Najipian Date: Wed, 21 Nov 2018 11:20:00 +0200 Subject: [PATCH 11/16] fix conflict merge issue --- app/handlers.py | 6 ------ app/modules/training/http_training.py | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/handlers.py b/app/handlers.py index 5e415eb..2730278 100755 --- a/app/handlers.py +++ b/app/handlers.py @@ -5,10 +5,7 @@ from app.modules.examples.yaml_example import YamlExampleHandler from app.modules.training.pipeline_training import PipelineTrainigHandler from app.modules.training.http_training import HttpTrainingHandler -<<<<<<< HEAD -======= from app.modules.training.datastore_training import DatastoreTrainingHandler ->>>>>>> datastore-training def handlers(): return [ @@ -23,9 +20,6 @@ def handlers(): (r'/examples/yaml', YamlExampleHandler), (r'/training/pipeline/(\d+)', PipelineTrainigHandler), (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), -<<<<<<< HEAD -======= (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), (r'/training/datastore', DatastoreTrainingHandler), ->>>>>>> datastore-training ] diff --git a/app/modules/training/http_training.py b/app/modules/training/http_training.py index 0131348..f16e826 100644 --- a/app/modules/training/http_training.py +++ b/app/modules/training/http_training.py @@ -13,8 +13,7 @@ def get(self, lat = None, lon = None): logging.info("HttpTrainingHandler get(%s,%s)" % (lat, lon)) # wikipedia base api url - API_HOST = "http://en.wikipedia.org/w/api.php?" - + API_HOST = "https://en.wikipedia.org/w/api.php?" # add given lat long to api url apiUrl = "%sformat=json&action=query&prop=extracts&exintro=1&explaintext=1&exlimit=20&generator=geosearch&ggsradius=10000&ggslimit=100&ggscoord=%s%s%s" % (API_HOST, lat,"|", lon) From 5a2685720eb9f06a7f91a0fa9500789528e9cbf5 Mon Sep 17 00:00:00 2001 From: Najipian Date: Wed, 21 Nov 2018 14:00:46 +0200 Subject: [PATCH 12/16] detect user coordinates --- app/handlers.py | 3 +-- app/modules/home.html | 2 +- app/modules/home.py | 19 +++++++++++++++++-- requirements.txt | 1 + 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/handlers.py b/app/handlers.py index 2730278..5a90068 100755 --- a/app/handlers.py +++ b/app/handlers.py @@ -19,7 +19,6 @@ def handlers(): (r'/examples/datastore/([^\/]+)/([^\/]+)', DatastoreExampleHandler), (r'/examples/yaml', YamlExampleHandler), (r'/training/pipeline/(\d+)', PipelineTrainigHandler), - (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), - (r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler), + (r'/training/http/([-?\d\.]+)/([-?\d\.]+)', HttpTrainingHandler), (r'/training/datastore', DatastoreTrainingHandler), ] diff --git a/app/modules/home.html b/app/modules/home.html index f363919..1a9f690 100755 --- a/app/modules/home.html +++ b/app/modules/home.html @@ -9,7 +9,7 @@

    Home

  • Datastore example (load)
  • Yaml example
  • Pipeline training
  • -
  • Http training
  • +
  • Http training
  • Datastore training
  • Logged in as : {{user_name}}

    diff --git a/app/modules/home.py b/app/modules/home.py index 3c1e726..c62a962 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -1,7 +1,7 @@ import webapp2 import logging import os - +import geocoder from google.appengine.ext.webapp import template from google.appengine.api import users @@ -9,9 +9,24 @@ class HomeHandler(webapp2.RequestHandler): def get(self): logging.info("HomeHandler get()") + logging.info(self.request.remote_addr) + + g = geocoder.ip(self.request.remote_addr) + + + if not g.latlng: + lat = -84.339880 + lng = 82.951710 + else: + lat = g.latlng[0] + lng = g.latlng[1] + + logging.info(lat) + logging.info(lng) + # get logged in user user = users.get_current_user() template_path = os.path.join(os.path.dirname(__file__), 'home.html') - self.response.write(template.render(template_path, {'user_name' : user.nickname() })) + self.response.write(template.render(template_path, {'user_name' : user.nickname() , 'lat' : lat , 'lng' : lng})) diff --git a/requirements.txt b/requirements.txt index d7b2f4b..a3e8c2a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ GoogleAppEnginePipeline GoogleAppEngineCloudStorageClient requests requests_toolbelt +geocoder \ No newline at end of file From 056926dd818134158a3df87e165e808ecb0dd8e2 Mon Sep 17 00:00:00 2001 From: Najipian Date: Wed, 21 Nov 2018 14:02:13 +0200 Subject: [PATCH 13/16] detect user coordinates --- app/modules/home.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/home.py b/app/modules/home.py index c62a962..3ac5227 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -15,8 +15,8 @@ def get(self): if not g.latlng: - lat = -84.339880 - lng = 82.951710 + lat = 30.0355 + lng = 31.223 else: lat = g.latlng[0] lng = g.latlng[1] From cc2eac33358107d6974f1ea9a62e18fc198fb60c Mon Sep 17 00:00:00 2001 From: Najipian Date: Wed, 21 Nov 2018 14:06:19 +0200 Subject: [PATCH 14/16] clean code --- app/modules/common/kinds.py | 1 - app/modules/home.py | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/modules/common/kinds.py b/app/modules/common/kinds.py index 00c8a0e..0d5c1c6 100644 --- a/app/modules/common/kinds.py +++ b/app/modules/common/kinds.py @@ -2,6 +2,5 @@ import logging from google.appengine.ext import ndb - class Example(ndb.Model): value = ndb.StringProperty() \ No newline at end of file diff --git a/app/modules/home.py b/app/modules/home.py index 3ac5227..7955d71 100644 --- a/app/modules/home.py +++ b/app/modules/home.py @@ -9,24 +9,20 @@ class HomeHandler(webapp2.RequestHandler): def get(self): logging.info("HomeHandler get()") - logging.info(self.request.remote_addr) + # get logged in user + user = users.get_current_user() + # get user coordinates via user ip g = geocoder.ip(self.request.remote_addr) - if not g.latlng: + # if user coordinates is not detected locate in cairo lat = 30.0355 lng = 31.223 else: lat = g.latlng[0] lng = g.latlng[1] - - logging.info(lat) - logging.info(lng) - # get logged in user - user = users.get_current_user() - template_path = os.path.join(os.path.dirname(__file__), 'home.html') self.response.write(template.render(template_path, {'user_name' : user.nickname() , 'lat' : lat , 'lng' : lng})) From bbd7d60f23893fb5efe3924e8287279a29c4417a Mon Sep 17 00:00:00 2001 From: Najipian Date: Thu, 22 Nov 2018 18:47:01 +0200 Subject: [PATCH 15/16] fix datastore-training reviews --- app/modules/common/kinds.py | 1 - app/modules/home.html | 4 ++-- app/modules/training/datastore_training.html | 12 ++++++++---- app/modules/training/datastore_training.py | 6 ++++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/modules/common/kinds.py b/app/modules/common/kinds.py index 0d5c1c6..a227189 100644 --- a/app/modules/common/kinds.py +++ b/app/modules/common/kinds.py @@ -1,4 +1,3 @@ -import webapp2 import logging from google.appengine.ext import ndb diff --git a/app/modules/home.html b/app/modules/home.html index 1a9f690..5a855ce 100755 --- a/app/modules/home.html +++ b/app/modules/home.html @@ -9,8 +9,8 @@

    Home

  • Datastore example (load)
  • Yaml example
  • Pipeline training
  • -
  • Http training
  • -
  • Datastore training
  • +
  • Http training
  • +
  • Datastore training
  • Logged in as : {{user_name}}

    diff --git a/app/modules/training/datastore_training.html b/app/modules/training/datastore_training.html index 597cf8f..0b8ea91 100644 --- a/app/modules/training/datastore_training.html +++ b/app/modules/training/datastore_training.html @@ -2,10 +2,14 @@

    Datastore Training

    - {% for entity in entities %} -

    {{ entity.key }}

    -

    {{ entity.value }}

    - {% endfor %} + + {% for entity in entities %} +

    {{ entity.key }}

    +

    {{ entity.value }}

    + {% endfor %} + {% if not entities %} + No entities found + {% endif %}
    diff --git a/app/modules/training/datastore_training.py b/app/modules/training/datastore_training.py index 1d2001e..e7b9aa2 100644 --- a/app/modules/training/datastore_training.py +++ b/app/modules/training/datastore_training.py @@ -1,7 +1,7 @@ import webapp2 import logging import os -from google.appengine.ext import ndb + from google.appengine.ext.webapp import template from app.modules.common.kinds import Example @@ -9,8 +9,10 @@ class DatastoreTrainingHandler(webapp2.RequestHandler): def get(self): logging.info("DatastoreTrainingHandler") + LIST_DEFAULT_LIMIT = 20 + # get entities - entities_for_example_kind = Example.query().fetch(20) + entities_for_example_kind = Example.query().fetch(LIST_DEFAULT_LIMIT) # make a list of key value pairs entities = [] From 5ba71dfb808113a6eb2af92848d6896013dfdf4a Mon Sep 17 00:00:00 2001 From: Najipian Date: Mon, 3 Dec 2018 11:39:24 +0200 Subject: [PATCH 16/16] datastore-training reviews --- app/modules/common/kinds.py | 1 - app/modules/training/datastore_training.html | 9 ++++----- app/modules/training/datastore_training.py | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/modules/common/kinds.py b/app/modules/common/kinds.py index a227189..6d2927b 100644 --- a/app/modules/common/kinds.py +++ b/app/modules/common/kinds.py @@ -1,4 +1,3 @@ -import logging from google.appengine.ext import ndb class Example(ndb.Model): diff --git a/app/modules/training/datastore_training.html b/app/modules/training/datastore_training.html index 0b8ea91..d125b88 100644 --- a/app/modules/training/datastore_training.html +++ b/app/modules/training/datastore_training.html @@ -2,11 +2,10 @@

    Datastore Training

    - - {% for entity in entities %} -

    {{ entity.key }}

    -

    {{ entity.value }}

    - {% endfor %} + {% for entity in entities %} +

    {{ entity.key }}

    +

    {{ entity.value }}

    + {% endfor %} {% if not entities %} No entities found {% endif %} diff --git a/app/modules/training/datastore_training.py b/app/modules/training/datastore_training.py index e7b9aa2..dbfaadb 100644 --- a/app/modules/training/datastore_training.py +++ b/app/modules/training/datastore_training.py @@ -1,7 +1,6 @@ import webapp2 import logging import os - from google.appengine.ext.webapp import template from app.modules.common.kinds import Example