diff --git a/backend/Py.Dockerfile b/backend/Py.Dockerfile index 90dff4c..e1b44c4 100644 --- a/backend/Py.Dockerfile +++ b/backend/Py.Dockerfile @@ -1,10 +1,10 @@ FROM continuumio/miniconda3 as build -WORKDIR /app +WORKDIR /app/ -COPY ./python /app/src +COPY ./python/ /app/src/ -RUN conda env create -f src/environment.yml +RUN conda env create -f ./src/environment.yml #RUN echo "conda activate cryptos" >> ~/.bashrc #SHELL ["/bin/bash", "--login", "-c"] @@ -12,7 +12,7 @@ RUN conda env create -f src/environment.yml RUN conda install -c conda-forge conda-pack RUN conda pack -n cryptos -o /tmp/env.tar && \ - mkdir /venv && cd /venv && tar xf /tmp/env.tar && \ + mkdir /venv/ && cd /venv/ && tar xf /tmp/env.tar && \ rm /tmp/env.tar RUN /venv/bin/conda-unpack @@ -20,18 +20,18 @@ RUN /venv/bin/conda-unpack FROM python:buster as runtime -WORKDIR /app +WORKDIR /app/ -COPY ./python /app/src -COPY ./api/bin /app/bin +COPY ./python/ /app/src/ +COPY ./automation/bin/ /app/bin/ -COPY --from=build /venv /venv +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 +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" ] diff --git a/backend/python/coingecko.py b/backend/python/coingecko.py index 53c9ba3..b6b5393 100644 --- a/backend/python/coingecko.py +++ b/backend/python/coingecko.py @@ -6,6 +6,8 @@ import datetime class CoinGecko: def __init__(self, base_url: str = None): + print('Creating object CoinGecko') + if base_url is None: base_url = 'https://api.coingecko.com/api/v3' self.base_url = base_url @@ -30,10 +32,14 @@ class CoinGecko: return json.loads(resp.text) def list(self): + print('Getting list of coins from {}'.format(self.base_url)) + url = self.__build_url('coins/list') return self.__get(url) def get(self, ids: tuple, currencies: tuple, last_updated: bool = True): + print('Getting {} in {} from {}'.format(ids, currencies, self.base_url)) + sub = 'simple/price' query = '&'.join([ '='.join(['ids', ','.join(ids)]), @@ -48,6 +54,8 @@ class CoinGecko: return res def historical(self, id_: str, currency: str, from_: str, to: str): + print('Getting historical data for {} in {} from {} to {} from {}'.format(id_, currency, from_, to, self.base_url)) + sub = '/'.join([ 'coins', id_, @@ -75,16 +83,19 @@ if __name__ == '__main__': hparser.add_argument('-f', '--from_') hparser.add_argument('-t', '--to') args = parser.parse_args() + + print('Called with args: {}'.format(vars(args))) + cg = CoinGecko(args.url) _ids = tuple(args.ids.split(',')) _currencies = tuple(args.currencies.split(',')) if 'historical' in args and args.historical: - from_ = args.from_ - if '-' in from_: - from_ = str(datetime.datetime.fromisoformat(from_).timestamp()) - to = args.to - if '-' in to: - to = str(datetime.datetime.fromisoformat(to).timestamp()) - print(cg.historical(id_=_ids[0], currency=_currencies[0], from_=from_, to=to)) + from__ = args.from_ + if '-' in from__: + from__ = str(datetime.datetime.fromisoformat(from__).timestamp()) + to_ = args.to + if '-' in to_: + to_ = str(datetime.datetime.fromisoformat(to_).timestamp()) + print(cg.historical(id_=_ids[0], currency=_currencies[0], from_=from__, to=to_)) exit() print(cg.get(ids=_ids, currencies=_currencies)) diff --git a/backend/python/miindicador.py b/backend/python/miindicador.py index e997d5e..0fc61bd 100644 --- a/backend/python/miindicador.py +++ b/backend/python/miindicador.py @@ -6,6 +6,8 @@ import datetime class MiIndicador: def __init__(self, base_url: str = None): + print('Creating object Mindicador') + if base_url is None: base_url = 'https://mindicador.cl/api' self.base_url = base_url @@ -30,10 +32,14 @@ class MiIndicador: return json.loads(resp.text) def list(self): + print('List possible indicators') + url = self.__build_url('') return self.__get(url) def get(self, indicador: str, fecha: str = None): + print('Getting {} in date {} from {}'.format(indicador, fecha, self.base_url)) + url = indicador if fecha is not None: url = '/'.join([url, fecha]) @@ -45,6 +51,8 @@ class MiIndicador: return res def historical(self, indicador: str, since: str = None): + print('Getting historical data for {} since {} from {}'.format(indicador, since, self.base_url)) + sub = indicador if since is not None: sub = '/'.join([sub, since]) @@ -65,6 +73,9 @@ if __name__ == '__main__': hparser.add_argument('-hi', '--historical', action='store_true') hparser.add_argument('-s', '--since') args = parser.parse_args() + + print('Called with args: {}'.format(vars(args))) + mi = MiIndicador(args.url) if 'historical' in args and args.historical: print(mi.historical(args.indicador, args.since))