11import logging
2+ import os
23from datetime import date
34from importlib import metadata
45
56import click
67from dotenv import load_dotenv
78from lightman_ai .ai .utils import AGENT_CHOICES
8- from lightman_ai .constants import DEFAULT_CONFIG_FILE , DEFAULT_CONFIG_SECTION , DEFAULT_ENV_FILE
9+ from lightman_ai .constants import (
10+ DEFAULT_AGENT ,
11+ DEFAULT_CONFIG_FILE ,
12+ DEFAULT_CONFIG_SECTION ,
13+ DEFAULT_ENV_FILE ,
14+ DEFAULT_LOG_LEVEL ,
15+ DEFAULT_SCORE ,
16+ DEFAULT_TIME_ZONE ,
17+ VERBOSE_LOG_LEVEL ,
18+ )
919from lightman_ai .core .config import FileConfig , FinalConfig , PromptConfig
1020from lightman_ai .core .exceptions import ConfigNotFoundError , InvalidConfigError , PromptNotFoundError
1121from lightman_ai .core .sentry import configure_sentry
12- from lightman_ai .core .settings import Settings
1322from lightman_ai .exceptions import MultipleDateSourcesError
1423from lightman_ai .main import lightman
1524from lightman_ai .utils import get_start_date
1625
1726logger = logging .getLogger ("lightman" )
27+ logging .basicConfig (
28+ format = "%(asctime)s [%(levelname)s] %(name)s: %(message)s" ,
29+ datefmt = "%Y-%m-%d %H:%M:%S" ,
30+ )
1831
1932
2033def get_version () -> str :
@@ -72,6 +85,7 @@ def entry_point() -> None:
7285@click .option ("--start-date" , type = click .DateTime (formats = ["%Y-%m-%d" ]), help = "Start date to retrieve articles" )
7386@click .option ("--today" , is_flag = True , help = "Retrieve articles from today." )
7487@click .option ("--yesterday" , is_flag = True , help = "Retrieve articles from yesterday." )
88+ @click .option ("-v" , is_flag = True , help = "Be more verbose on output." )
7589def run (
7690 agent : str ,
7791 prompt : str ,
@@ -85,18 +99,27 @@ def run(
8599 start_date : date | None ,
86100 today : bool ,
87101 yesterday : bool ,
102+ v : bool ,
88103) -> int :
89104 """
90105 Entrypoint of the application.
91106
92107 Holds no logic. It loads the configuration, calls the main method and returns 0 when succesful .
93108 """
94109 load_dotenv (env_file or DEFAULT_ENV_FILE )
95- configure_sentry ()
96110
97- settings = Settings .try_load_from_file (env_file )
111+ if v :
112+ log_level = VERBOSE_LOG_LEVEL
113+ else :
114+ env_log_level = os .getenv ("LOG_LEVEL" )
115+ log_level = env_log_level .upper () if env_log_level else DEFAULT_LOG_LEVEL
116+
117+ logger .setLevel (log_level )
118+
119+ configure_sentry (logger .level )
120+
98121 try :
99- start_datetime = get_start_date (settings , yesterday , today , start_date )
122+ start_datetime = get_start_date (os . getenv ( "TIME_ZONE" , DEFAULT_TIME_ZONE ) , yesterday , today , start_date )
100123 except MultipleDateSourcesError as e :
101124 raise click .UsageError (e .args [0 ]) from e
102125
@@ -105,9 +128,9 @@ def run(
105128 config_from_file = FileConfig .get_config_from_file (config_section = config , path = config_file )
106129 final_config = FinalConfig .init_from_dict (
107130 data = {
108- "agent" : agent or config_from_file .agent or settings . AGENT ,
131+ "agent" : agent or config_from_file .agent or DEFAULT_AGENT ,
109132 "prompt" : prompt or config_from_file .prompt ,
110- "score_threshold" : score or config_from_file .score_threshold or settings . SCORE ,
133+ "score_threshold" : score or config_from_file .score_threshold or DEFAULT_SCORE ,
111134 "model" : model or config_from_file .model ,
112135 }
113136 )
0 commit comments