From fb00726b9b2644250f12bb6de23f62248716f52e Mon Sep 17 00:00:00 2001 From: THIVEND Date: Wed, 9 Jun 2021 10:03:55 +0200 Subject: [PATCH 1/4] Add tests for app --- app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index d1c3270..4e60767 100644 --- a/app.py +++ b/app.py @@ -23,7 +23,8 @@ def wrapped(*args, **kwargs): return jsonify({'message': 'Token expired'}), 403 except jwt.exceptions.InvalidSignatureError: return jsonify({'message': 'Invalid token'}), 403 - + except Exception as e: + return jsonify({'message':e}) return func(*args, **kwargs) return wrapped From 4ae2aab0333e51e8d50977ddfb5d21ae04573136 Mon Sep 17 00:00:00 2001 From: THIVEND Date: Fri, 12 Nov 2021 10:59:59 +0100 Subject: [PATCH 2/4] Update to gunicorn webserver --- Dockerfile | 2 +- app.py | 3 +-- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 505873d..e0d7132 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,4 +16,4 @@ RUN pip3 install -r requirements.txt COPY . . EXPOSE 8080 ENV PORT 8080 -CMD python3 app.py +CMD gunicorn -w 4 --bind=0.0.0.0:${PORT} app:app --timeout=600 \ No newline at end of file diff --git a/app.py b/app.py index df4e859..2e1c1d5 100644 --- a/app.py +++ b/app.py @@ -62,5 +62,4 @@ def index(): if __name__ == "__main__": - from waitress import serve - serve(app, host="0.0.0.0", port=os.environ["PORT"]) + app.run() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index dffbd81..9dadb99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ coverage~=5.5 +gunicorn~=20.1.0 PyJWT~=2.0.1 pandas~=1.2.3 psycopg2~=2.9.1 @@ -11,4 +12,3 @@ pyyaml~=5.4.1 SQLAlchemy~=1.3.23 urllib3~=1.26.3 flask~=1.1.2 -waitress~=2.0.0 \ No newline at end of file From 17d9d0ae14af37548a594c98fc945ce281bd8877 Mon Sep 17 00:00:00 2001 From: THIVEND Date: Wed, 18 Jan 2023 08:34:32 +0100 Subject: [PATCH 3/4] Modify .dockerignore --- .dockerignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 842ed4a..c118800 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,4 +7,5 @@ README.md license.txt Dockerfile Makefile -*_matomo \ No newline at end of file +*_matomo +*.sql \ No newline at end of file From ec8064f1fb72683d518b6a895340a7ae8df468f8 Mon Sep 17 00:00:00 2001 From: THIVEND Date: Fri, 5 May 2023 10:30:37 +0200 Subject: [PATCH 4/4] Remove .env.local --- .env.local | 5 ----- matomo_pull/settings.py | 4 ++-- matomo_pull/sql_handling.py | 3 ++- tests/test_settings.py | 8 ++++---- 4 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 .env.local diff --git a/.env.local b/.env.local deleted file mode 100644 index 7b8b273..0000000 --- a/.env.local +++ /dev/null @@ -1,5 +0,0 @@ -base_url=https://argus.osp.cat/ -db_name=renew-europe_matomo -id_site=150 -start_date=2021-09-30 -token_auth=52d31067f1a821f808950ac54daa4c68 \ No newline at end of file diff --git a/matomo_pull/settings.py b/matomo_pull/settings.py index a0b7837..b18bf78 100644 --- a/matomo_pull/settings.py +++ b/matomo_pull/settings.py @@ -116,7 +116,7 @@ def update_dates(mtm_vars): return mtm_vars -def is_database_created(table_name='visits'): +def is_database_created(table_name='matomo.visits'): try: return bool(connection.execute(f"select * from {table_name}")) except Exception: @@ -127,7 +127,7 @@ def update_start_date_regarding_database_state(mtm_vars): if is_database_created(): last_update = ( connection.execute( - "select date from visits order by date desc limit 1" + "select date from matomo.visits order by date desc limit 1" ).fetchall()[0][0] ).date() return last_update + timedelta(days=1) diff --git a/matomo_pull/sql_handling.py b/matomo_pull/sql_handling.py index f2436eb..2b553a5 100644 --- a/matomo_pull/sql_handling.py +++ b/matomo_pull/sql_handling.py @@ -35,6 +35,7 @@ def convert_data_object_to_sql(table_name, table_params, data_object): df.to_sql( table_name, s.connection, - if_exists='append' + if_exists='append', + schema='matomo' ) print(table_name) diff --git a/tests/test_settings.py b/tests/test_settings.py index 2377701..2e4fb18 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -54,11 +54,11 @@ def test_database_already_up_to_date(settings_setup, monkeypatch): def test_database_creation(settings_setup): conn = settings.set_database_connection(os.environ['db_name']) conn.execute( - "create table visits(id int primary key not null, date date);" + "create table matomo.visits(id int primary key not null, date date);" ) assert settings.is_database_created() - conn.execute("drop table visits;") + conn.execute("drop table matomo.visits;") assert not settings.is_database_created() @@ -69,10 +69,10 @@ def test_updating_dates(settings_setup): conn = settings.set_database_connection(os.environ['db_name']) conn.execute( - "create table visits(id int primary key not null, date timestamp);" + "create table matomo.visits(id int primary key not null, date timestamp);" ) conn.execute( - f"insert into visits(id,date) values(1, '{last_update_date}')" + f"insert into matomo.visits(id,date) values(1, '{last_update_date}')" ) vars = settings.check_mtm_vars(settings.mtm_vars)