diff --git a/python/flask/Dockerfile b/python/flask/Dockerfile new file mode 100644 index 00000000..2fa70744 --- /dev/null +++ b/python/flask/Dockerfile @@ -0,0 +1,8 @@ +FROM node:12-alpine +RUN apk add --no-cache python2 g++ make +WORKDIR /home/ubuntu/idonate/trace-examples/python/flask +COPY . . +RUN yarn install --production +CMD ["python", "run", "python", "run.py"] + + diff --git a/python/flask/Pipfile b/python/flask/Pipfile index bfce5f95..e1494ff6 100644 --- a/python/flask/Pipfile +++ b/python/flask/Pipfile @@ -11,6 +11,7 @@ requests = "*" flask-caching = "*" flask-cors = "*" flask-limiter = "*" +pyunsplash = "*" [dev-packages] diff --git a/python/flask/Pipfile.lock b/python/flask/Pipfile.lock deleted file mode 100644 index 3207621c..00000000 --- a/python/flask/Pipfile.lock +++ /dev/null @@ -1,161 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "e7f17e9aa890185fe0da606bccf111db51e01f98d9c572cb545b2aa8a9e6e378" - }, - "pipfile-spec": 6, - "requires": { - "python_version": "3.7" - }, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "blinker": { - "hashes": [ - "sha256:471aee25f3992bd325afa3772f1063dbdbbca947a041b8b89466dc00d606f8b6" - ], - "index": "pypi", - "version": "==1.4" - }, - "certifi": { - "hashes": [ - "sha256:339dc09518b07e2fa7eda5450740925974815557727d6bd35d319c1524a04a4c", - "sha256:6d58c986d22b038c8c0df30d639f23a3e6d172a05c3583e766f4c0b785c0986a" - ], - "version": "==2018.10.15" - }, - "chardet": { - "hashes": [ - "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", - "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" - ], - "version": "==3.0.4" - }, - "click": { - "hashes": [ - "sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13", - "sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7" - ], - "version": "==7.0" - }, - "ddtrace": { - "hashes": [ - "sha256:7bfd9c4bcec1cfdeeccc8204f6f35fcd84dc552c57c90bf93364e4d62d32f7d3" - ], - "index": "pypi", - "version": "==0.15.0" - }, - "flask": { - "hashes": [ - "sha256:2271c0070dbcb5275fad4a82e29f23ab92682dc45f9dfbc22c02ba9b9322ce48", - "sha256:a080b744b7e345ccfcbc77954861cb05b3c63786e93f2b3875e0913d44b43f05" - ], - "index": "pypi", - "version": "==1.0.2" - }, - "flask-caching": { - "hashes": [ - "sha256:44fe827c6cc519d48fb0945fa05ae3d128af9a98f2a6e71d4702fd512534f227", - "sha256:e34f24631ba240e09fe6241e1bf652863e0cff06a1a94598e23be526bc2e4985" - ], - "index": "pypi", - "version": "==1.4.0" - }, - "flask-cors": { - "hashes": [ - "sha256:e4c8fc15d3e4b4cce6d3b325f2bab91e0e09811a61f50d7a53493bc44242a4f1", - "sha256:ecc016c5b32fa5da813ec8d272941cfddf5f6bba9060c405a70285415cbf24c9" - ], - "index": "pypi", - "version": "==3.0.6" - }, - "flask-limiter": { - "hashes": [ - "sha256:8cce98dcf25bf2ddbb824c2b503b4fc8e1a139154240fd2c60d9306bad8a0db8" - ], - "index": "pypi", - "version": "==1.0.1" - }, - "idna": { - "hashes": [ - "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", - "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16" - ], - "version": "==2.7" - }, - "itsdangerous": { - "hashes": [ - "sha256:cbb3fcf8d3e33df861709ecaf89d9e6629cff0a217bc2848f1b41cd30d360519" - ], - "version": "==0.24" - }, - "jinja2": { - "hashes": [ - "sha256:74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd", - "sha256:f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4" - ], - "version": "==2.10" - }, - "limits": { - "hashes": [ - "sha256:9df578f4161017d79f5188609f1d65f6b639f8aad2914c3960c9252e56a0ff95", - "sha256:a017b8d9e9da6761f4574642149c337f8f540d4edfe573fb91ad2c4001a2bc76" - ], - "version": "==1.3" - }, - "markupsafe": { - "hashes": [ - "sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665" - ], - "version": "==1.0" - }, - "msgpack-python": { - "hashes": [ - "sha256:378cc8a6d3545b532dfd149da715abae4fda2a3adb6d74e525d0d5e51f46909b" - ], - "version": "==0.5.6" - }, - "requests": { - "hashes": [ - "sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c", - "sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279" - ], - "index": "pypi", - "version": "==2.20.0" - }, - "six": { - "hashes": [ - "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", - "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" - ], - "version": "==1.11.0" - }, - "urllib3": { - "hashes": [ - "sha256:41c3db2fc01e5b907288010dec72f9d0a74e37d6994e6eb56849f59fea2265ae", - "sha256:8819bba37a02d143296a4d032373c4dd4aca11f6d4c9973335ca75f9c8475f59" - ], - "version": "==1.24" - }, - "werkzeug": { - "hashes": [ - "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c", - "sha256:d5da73735293558eb1651ee2fddc4d0dedcfa06538b8813a2e20011583c9e49b" - ], - "version": "==0.14.1" - }, - "wrapt": { - "hashes": [ - "sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6" - ], - "version": "==1.10.11" - } - }, - "develop": {} -} diff --git a/python/flask/app/app.py b/python/flask/app/app.py index 76bf762c..dd981789 100644 --- a/python/flask/app/app.py +++ b/python/flask/app/app.py @@ -19,6 +19,9 @@ # Utilities import requests +#Images +from pyunsplash import PyUnsplash + # Internal from .blueprint import bp from .exceptions import AppException @@ -90,6 +93,14 @@ def index(): dict(label='GET /', url=url_for('index')), ], ), + dict( + rule='GET /image', + description=[ + 'Endpoint to retrieve an image from the PyUnsplash library.' + ], + links=[dict(label='GET /image', url=url_for('image')), + ], + ), dict( rule='GET /joke', description=[ @@ -190,6 +201,22 @@ def index(): ] return render_template('index.jinja2', routes=routes) +# Endpoint which retrieves an image +@app.route('/image') +def image(): + pyuns = PyUnsplash(api_key="aGkM_2OSlblMITvJXOelIs6kWPcbgT_F7U07phUPYdU") + photos = pyuns.photos(type_='random', count=1, featured=True, query="splash") + [photo] = photos.entries + print(photo.id, photo.link_download) + + @after_this_request + def after_image(response): + print('HOOK: after_this_request') + return response + + return photo.link_download + + # Endpoint which makes uses `requests` @app.route('/joke') diff --git a/python/flask/run.sh b/python/flask/run.sh new file mode 100755 index 00000000..603a3154 --- /dev/null +++ b/python/flask/run.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +docker run --name mynginx1 -p 80:5000 -d nginx +docker run --name idonate1 idonate +docker run --name idonate2 idonate +docker run --name idonate3 idonate +