Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Adding pipeline stdout class #125

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading