├── .gitignore ├── Dockerfile ├── README.md ├── app.py ├── pokeapi.db ├── pokeapi.py ├── requirements.txt └── templates └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | response-cache/ -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3 2 | 3 | # Copy the current directory contents into the container at /app 4 | COPY . /usr/src/app 5 | 6 | # Set the working directory to /usr/src/app 7 | WORKDIR /usr/src/app 8 | 9 | # Install any needed packages specified in requirements.txt 10 | RUN pip install --no-cache-dir -r requirements.txt 11 | 12 | # Make port 5000 available to the world outside this container 13 | EXPOSE 5000 14 | 15 | # run the command 16 | CMD [ "python", "./app.py" ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Poke Python 2 | ===================================== 3 | 4 | Pretty small and simple application to show the advantages of docker. 5 | 6 | Run the container with `docker run -it -p 5000:5000 anhellojz/pokepy:3.0`. 7 | 8 | See the image at https://hub.docker.com/repository/docker/anhellojz/pokepy. 9 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | from pokeapi import PokeAPI 3 | from random import randrange 4 | 5 | app = Flask(__name__) 6 | api = PokeAPI() 7 | 8 | @app.route('/') 9 | def index(): 10 | pokemon = api.getPokemon(randrange(152)) 11 | return render_template('index.html', pokemon=pokemon) 12 | 13 | if __name__ == "__main__": 14 | app.run(host="0.0.0.0") 15 | -------------------------------------------------------------------------------- /pokeapi.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnhellO/pokepy/8b4f59f4b8ac6ad2097e493fb3c878ba55fad0c0/pokeapi.db -------------------------------------------------------------------------------- /pokeapi.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | from random import randrange 4 | 5 | class PokeAPI(object): 6 | 7 | def __init__(self): 8 | self.ENDPOINT = 'https://pokeapi.co/api/v2/pokemon' 9 | 10 | def getPokemon(self, x): 11 | uri = f'{self.ENDPOINT}/{x}' 12 | r = requests.get(uri) 13 | data = r.json() 14 | 15 | return { 16 | 'name': data.get('name'), 17 | 'image': data.get('sprites', {}).get('front_default'), 18 | } 19 | 20 | 21 | # api = PokeAPI() 22 | # print(json.dumps(api.getPokemon(randrange(10)), indent=2)) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask==1.1.1 2 | requests==2.22.0 -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 18 | 19 | 20 |