Commit a9be9ffb authored by Christophe Benz's avatar Christophe Benz

Use Flask-Matomo

parent 66a1f664
...@@ -13,4 +13,9 @@ SHIELDS_IO_BASE_URL="https://img.shields.io/" ...@@ -13,4 +13,9 @@ SHIELDS_IO_BASE_URL="https://img.shields.io/"
API_VALIDATE_ENDPOINT=http://127.0.0.1:5600/validate API_VALIDATE_ENDPOINT=http://127.0.0.1:5600/validate
# Homepage sections and blocks config file path # Homepage sections and blocks config file path
# HOMEPAGE_CONFIG_FILE=homepage_config.json # HOMEPAGE_CONFIG_FILE=homepage_config.json
\ No newline at end of file
# If used, do "pip install validata-api[matomo]"
# MATOMO_AUTH_TOKEN=""
# MATOMO_BASE_URL=""
# MATOMO_SITE_ID=""
...@@ -3,6 +3,7 @@ cachecontrol==0.12.5 ...@@ -3,6 +3,7 @@ cachecontrol==0.12.5
commonmark==0.8.1 commonmark==0.8.1
ezodf==0.3.2 ezodf==0.3.2
Flask==1.0.2 Flask==1.0.2
Flask-Matomo==1.2.0
lxml==4.2.5 lxml==4.2.5
opendataschema==0.2.0 opendataschema==0.2.0
python-dotenv==0.10.1 python-dotenv==0.10.1
......
...@@ -67,4 +67,8 @@ setup( ...@@ -67,4 +67,8 @@ setup(
'opendataschema >= 0.2.0, < 0.3', 'opendataschema >= 0.2.0, < 0.3',
'validata_core >= 0.3.0, < 0.4', 'validata_core >= 0.3.0, < 0.4',
], ],
extras_require={
'matomo': ["Flask-Matomo"],
},
) )
...@@ -4,12 +4,12 @@ import os ...@@ -4,12 +4,12 @@ import os
from pathlib import Path from pathlib import Path
from urllib.parse import quote_plus from urllib.parse import quote_plus
import cachecontrol
import flask import flask
import jinja2 import jinja2
import requests import requests
import tableschema import tableschema
import cachecontrol
import opendataschema import opendataschema
from . import config from . import config
...@@ -45,6 +45,11 @@ if config.HOMEPAGE_CONFIG: ...@@ -45,6 +45,11 @@ if config.HOMEPAGE_CONFIG:
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.secret_key = config.SECRET_KEY app.secret_key = config.SECRET_KEY
matomo = None
if config.MATOMO_AUTH_TOKEN and config.MATOMO_BASE_URL and config.MATOMO_SITE_ID:
from flask_matomo import Matomo
matomo = Matomo(app, matomo_url=config.MATOMO_BASE_URL,
id_site=config.MATOMO_SITE_ID, token_auth=config.MATOMO_AUTH_TOKEN)
# Jinja2 url_quote_plus custom filter # Jinja2 url_quote_plus custom filter
# https://stackoverflow.com/questions/12288454/how-to-import-custom-jinja2-filters-from-another-file-and-using-flask # https://stackoverflow.com/questions/12288454/how-to-import-custom-jinja2-filters-from-another-file-and-using-flask
......
...@@ -50,3 +50,9 @@ if HOMEPAGE_CONFIG_FILE: ...@@ -50,3 +50,9 @@ if HOMEPAGE_CONFIG_FILE:
HOMEPAGE_CONFIG_FILE = Path(HOMEPAGE_CONFIG_FILE) HOMEPAGE_CONFIG_FILE = Path(HOMEPAGE_CONFIG_FILE)
with HOMEPAGE_CONFIG_FILE.open() as fd: with HOMEPAGE_CONFIG_FILE.open() as fd:
HOMEPAGE_CONFIG = json.load(fd) HOMEPAGE_CONFIG = json.load(fd)
MATOMO_AUTH_TOKEN = os.getenv("MATOMO_AUTH_TOKEN") or None
MATOMO_BASE_URL = os.getenv("MATOMO_BASE_URL") or None
MATOMO_SITE_ID = os.getenv("MATOMO_SITE_ID") or None
if MATOMO_SITE_ID:
MATOMO_SITE_ID = int(MATOMO_SITE_ID)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment