Python with Flask
This commit is contained in:
@ -1,37 +1,13 @@
|
|||||||
FROM continuumio/miniconda3 as build
|
FROM python:3.9 as runtime
|
||||||
|
|
||||||
WORKDIR /app/
|
WORKDIR /app/
|
||||||
|
|
||||||
COPY ./python/ /app/src/
|
COPY ./python/ /app/
|
||||||
|
|
||||||
RUN conda env create -f ./src/environment.yml
|
RUN python -m pip install gunicorn httpx flask
|
||||||
|
|
||||||
#RUN echo "conda activate cryptos" >> ~/.bashrc
|
EXPOSE 5001
|
||||||
#SHELL ["/bin/bash", "--login", "-c"]
|
|
||||||
|
|
||||||
RUN conda install -c conda-forge conda-pack
|
CMD ["gunicorn", "-b", "0.0.0.0:5001", "crypto.index:app"]
|
||||||
|
|
||||||
RUN conda pack -n cryptos -o /tmp/env.tar && \
|
#ENTRYPOINT [ "/bin/bash" ]
|
||||||
mkdir /venv/ && cd /venv/ && tar xf /tmp/env.tar && \
|
|
||||||
rm /tmp/env.tar
|
|
||||||
|
|
||||||
RUN /venv/bin/conda-unpack
|
|
||||||
|
|
||||||
|
|
||||||
FROM python:buster as runtime
|
|
||||||
|
|
||||||
WORKDIR /app/
|
|
||||||
|
|
||||||
COPY ./python/ /app/src/
|
|
||||||
COPY ./automation/bin/ /app/bin/
|
|
||||||
|
|
||||||
COPY --from=build /venv/ /venv/
|
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-c"]
|
|
||||||
|
|
||||||
RUN pip install pyinstaller
|
|
||||||
|
|
||||||
RUN pyinstaller -F -n coingecko --clean --log-level DEBUG --distpath /app/bin/ /app/src/coingecko.py && \
|
|
||||||
pyinstaller -F -n mindicador --clean --log-level DEBUG --distpath /app/bin/ /app/src/miindicador.py
|
|
||||||
|
|
||||||
ENTRYPOINT [ "/bin/bash" ]
|
|
||||||
|
Binary file not shown.
Binary file not shown.
BIN
backend/python/crypto/__pycache__/coingecko.cpython-39.pyc
Normal file
BIN
backend/python/crypto/__pycache__/coingecko.cpython-39.pyc
Normal file
Binary file not shown.
BIN
backend/python/crypto/__pycache__/index.cpython-39.pyc
Normal file
BIN
backend/python/crypto/__pycache__/index.cpython-39.pyc
Normal file
Binary file not shown.
BIN
backend/python/crypto/__pycache__/miindicador.cpython-39.pyc
Normal file
BIN
backend/python/crypto/__pycache__/miindicador.cpython-39.pyc
Normal file
Binary file not shown.
50
backend/python/crypto/index.py
Normal file
50
backend/python/crypto/index.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
from crypto.coingecko import CoinGecko
|
||||||
|
from crypto.miindicador import MiIndicador
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def main():
|
||||||
|
output = [
|
||||||
|
"<html>",
|
||||||
|
"<body>",
|
||||||
|
"Welcome",
|
||||||
|
"</body>",
|
||||||
|
"</html>"
|
||||||
|
]
|
||||||
|
return "\n".join(output)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/crypto/historical/<ids>/<from_>/<to>')
|
||||||
|
@app.route('/crypto/historical/<ids>/<from_>/<to>/<currencies>')
|
||||||
|
def historical_crypto(ids, from_, to, currencies='usd'):
|
||||||
|
cg = CoinGecko()
|
||||||
|
return cg.historical(id_=ids, from_=from_, to=to, currency=currencies)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/crypto/<ids>')
|
||||||
|
@app.route('/crypto/<ids>/<currencies>')
|
||||||
|
def crypto(ids, currencies=('usd', 'clp')):
|
||||||
|
cg = CoinGecko()
|
||||||
|
return cg.get(ids, currencies)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/indicador/historical/<ind>')
|
||||||
|
@app.route('/indicador/historical/<ind>/<since>')
|
||||||
|
def historical_indicador(ind, since=None):
|
||||||
|
mi = MiIndicador()
|
||||||
|
return mi.historical(ind, since)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/indicador/<ind>')
|
||||||
|
@app.route('/indicador/<ind>/<fecha>')
|
||||||
|
def indicador(ind, fecha=None):
|
||||||
|
mi = MiIndicador()
|
||||||
|
return mi.get(ind, fecha)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host='0.0.0.0', port=5001, debug=True)
|
@ -1,10 +0,0 @@
|
|||||||
name: cryptos
|
|
||||||
channels:
|
|
||||||
- defaults
|
|
||||||
dependencies:
|
|
||||||
- httpx=0.17.1
|
|
||||||
- pip=21.1.2
|
|
||||||
- python=3.9.5
|
|
||||||
- setuptools=52.0.0
|
|
||||||
# - pip:
|
|
||||||
# - pyinstaller==4.3
|
|
@ -1,30 +0,0 @@
|
|||||||
# This file may be used to create an environment using:
|
|
||||||
# $ conda create --name <env> --file <this file>
|
|
||||||
# platform: win-64
|
|
||||||
altgraph=0.17=pypi_0
|
|
||||||
ca-certificates=2021.5.25=haa95532_1
|
|
||||||
certifi=2021.5.30=py39haa95532_0
|
|
||||||
future=0.18.2=pypi_0
|
|
||||||
h11=0.12.0=pyhd3eb1b0_0
|
|
||||||
h2=4.0.0=py39haa95532_3
|
|
||||||
hpack=4.0.0=py_0
|
|
||||||
httpcore=0.12.3=pyhd3eb1b0_0
|
|
||||||
httpx=0.17.1=pyhd3eb1b0_0
|
|
||||||
hyperframe=6.0.1=pyhd3eb1b0_0
|
|
||||||
idna=2.10=pyhd3eb1b0_0
|
|
||||||
openssl=1.1.1k=h2bbff1b_0
|
|
||||||
pefile=2021.5.24=pypi_0
|
|
||||||
pip=21.1.2=py39haa95532_0
|
|
||||||
pyinstaller=4.3=pypi_0
|
|
||||||
pyinstaller-hooks-contrib=2021.1=pypi_0
|
|
||||||
python=3.9.5=h6244533_3
|
|
||||||
pywin32-ctypes=0.2.0=pypi_0
|
|
||||||
rfc3986=1.4.0=py_0
|
|
||||||
setuptools=52.0.0=py39haa95532_0
|
|
||||||
sniffio=1.2.0=py39haa95532_1
|
|
||||||
sqlite=3.35.4=h2bbff1b_0
|
|
||||||
tzdata=2020f=h52ac0ba_0
|
|
||||||
vc=14.2=h21ff451_1
|
|
||||||
vs2015_runtime=14.27.29016=h5e58377_2
|
|
||||||
wheel=0.36.2=pyhd3eb1b0_0
|
|
||||||
wincertstore=0.2=py39h2bbff1b_0
|
|
Reference in New Issue
Block a user