Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plewak idonate #117

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]


1 change: 1 addition & 0 deletions python/flask/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ requests = "*"
flask-caching = "*"
flask-cors = "*"
flask-limiter = "*"
pyunsplash = "*"

[dev-packages]

Expand Down
161 changes: 0 additions & 161 deletions python/flask/Pipfile.lock

This file was deleted.

27 changes: 27 additions & 0 deletions python/flask/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# Utilities
import requests

#Images
from pyunsplash import PyUnsplash

# Internal
from .blueprint import bp
from .exceptions import AppException
Expand Down Expand Up @@ -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=[
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions python/flask/run.sh
Original file line number Diff line number Diff line change
@@ -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