Skip to content

Commit

Permalink
Merge pull request #125 from tsugumi-sys/feature/imple-pipeline-stdou…
Browse files Browse the repository at this point in the history
…t-class

Core: Adding pipeline stdout class
  • Loading branch information
tsugumi-sys authored Jun 11, 2024
2 parents 89a7d76 + e746bf0 commit ebd4c81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 17 additions & 0 deletions stocklake/core/stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ def warning_message(self, message: str):
self.msg_colors.get("DEFAULT"),
)
)


class PipelineStdOut:
def __init__(self):
self.stdout = PrettyStdoutPrint()

def starting(self, pipeline_name: str):
self.stdout.step_start(f"Pipeline: {pipeline_name} is starting ...")

def skip_downloading(self):
self.stdout.warning_message("- Skip Downloading")

def downloading(self):
self.stdout.normal_message("- Downloading ...")

def completed(self):
self.stdout.success_message("- Completed🐳.")
12 changes: 6 additions & 6 deletions stocklake/nasdaqapi/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from stocklake.core.base_pipeline import BasePipeline
from stocklake.core.base_preprocessor import BasePreprocessor
from stocklake.core.base_store import BaseStore
from stocklake.core.stdout import PrettyStdoutPrint
from stocklake.core.stdout import PipelineStdOut
from stocklake.exceptions import StockLoaderException
from stocklake.nasdaqapi.constants import Exchange
from stocklake.nasdaqapi.data_loader import (
Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(
self.store_type = store_type
self.preprocessor = NASDAQSymbolsPreprocessor()
self.store = NASDAQDataStore(sqlalchemy_session)
self.stdout = PrettyStdoutPrint()
self.stdout = PipelineStdOut()

def run(self):
if self.exchange is None:
Expand Down Expand Up @@ -71,14 +71,14 @@ def _run(
preprocessor: BasePreprocessor,
store: BaseStore,
):
self.stdout.step_start(f"NASDAQ API for {exchange.upper()} exchange symbols")
self.stdout.starting(f"NASDAQ API of {exchange.upper()}")
if not self.skip_download:
self.stdout.normal_message("- Downloading ...")
self.stdout.downloading()
raw_data = data_loader.download()
else:
self.stdout.warning_message("- Skip Downloading")
self.stdout.skip_downloading()
# TODO: fetch from cached file
return
data = preprocessor.process(exchange, raw_data)
store.save(self.store_type, exchange, data)
self.stdout.success_message("- Completed🐳.")
self.stdout.completed()

0 comments on commit ebd4c81

Please sign in to comment.