Skip to content

Commit

Permalink
implement measurement protocol for google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Dert1129 committed Jul 31, 2024
1 parent d2d95a6 commit e632a33
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.*
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM python:3.7.12-alpine3.14
WORKDIR /code
ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers tzdata libffi-dev libc-dev
COPY app.py app.py
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN pip3 install -U flask-cors
Expand Down
24 changes: 10 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class MYSQLConnection:
def __init__(self):
logger.debug(
logger.info(
"Start: MYSQLConnection().__init__(), trying to load environment variables in docker"
)
self.host = None
Expand Down Expand Up @@ -99,11 +99,8 @@ def get_file_info_by_file_name(file_name):
"SELECT * FROM repo_file_v WHERE file_name = %s",
(file_name,),
)
# /api/v1/file/download/46669edb-0e3e-4470-8834-e9ca30a50bc3/

# 4a45bcae-3203-4319-b455-b28965b1587a_20240604_OpenAccessClinicalData.csv'

@app.route('/v1/file/download/<packageId>/<objectName>', methods=['GET'])
@app.route('/v1/file/download/<packageId>/<objectName>', methods=['POST', 'GET'])
def downloadFile(packageId, objectName):
result = get_file_info_by_file_name(objectName)
if result[0]["access"] == "open":
Expand All @@ -113,15 +110,14 @@ def downloadFile(packageId, objectName):
payload = {
"client_id": "XXXXXXXXXX.YYYYYYYYYY",
"events": [
{
"name": "file_download",
"params": {
"file_name": objectName[59:]
}
{
"name": "file_download",
"params": {
"file_name": objectName
}
]
}]
}
requests.post(url, json=payload, headers={'content-type': 'application/json'}, verify=True)
requests.post(url, json=payload, headers={"Content-Type": "application/json"})
return send_file(object, as_attachment=True, download_name=objectName)
except S3Error as err:
logger.error(err)
Expand All @@ -138,7 +134,7 @@ def downloadDerivedFileS3PS(packageId, objectName):
Params={'Bucket': s3Bucket, 'Key': objectNameFull},
ExpiresIn=3600)
except botocore.exceptions.ClientError as error:
logger.error(err)
logger.error(error)
except botocore.exceptions.ParamValidationError as error:
logger.error(err)
logger.error(error)

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ minio
boto3
flask-cors
mysql-connector-python
requests

0 comments on commit e632a33

Please sign in to comment.