Compare commits

..

2 Commits

Author SHA1 Message Date
c930ffc55e Logging for python files 2021-07-07 08:56:05 -04:00
8c870cb43f Env samples 2021-07-07 08:55:49 -04:00
7 changed files with 51 additions and 19 deletions

4
.common.env.sample Normal file
View File

@ -0,0 +1,4 @@
DEBUG=true
DB_HOST="db"
ENV='dev'
API_URL='http://localhost:8081'

4
.db.env.sample Normal file
View File

@ -0,0 +1,4 @@
MYSQL_ROOT_PASSWORD=
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DATABASE=

2
.env.sample Normal file
View File

@ -0,0 +1,2 @@
FRONTEND_PORT=#Port for frontend UI
BACKEND_PORT=#Port for backend app

View File

@ -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" ]

View File

@ -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))

View File

@ -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))

View File

@ -24,7 +24,7 @@ services:
build:
context: ./frontend
dockerfile: PHP.Dockerfile
env_file: common.env
env_file: .common.env
volumes:
- .:/app
depends_on:
@ -36,7 +36,7 @@ services:
context: ./backend
dockerfile: PHP.Dockerfile
env_file:
- common.env
- .common.env
- .db.env
volumes:
- .:/app