Skip to content

Commit 2845434

Browse files
author
chenjunjie
committed
🦄 refactor: move print_failed_query to utils
1 parent e49754f commit 2845434

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

opendigger_pycli/console/print_indicator.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .print_indicator_graph import print_base_data_graph, print_base_network_data_graph
77
from .print_indicator_json import print_base_data_json, print_base_network_data_json
88
from .print_indicator_table import print_base_data_table, print_base_network_data_table
9+
from .utils import print_failed_query
910

1011
if t.TYPE_CHECKING:
1112
from opendigger_pycli.datatypes import (
@@ -24,29 +25,6 @@ def format_indicator_name(indicator_name: str) -> str:
2425
return indicator_name.replace("_", " ").title()
2526

2627

27-
def print_failed_query(
28-
indicator_name: str, failed_query: t.Optional["IndicatorQuery"]
29-
) -> None:
30-
if failed_query is None:
31-
return
32-
33-
if failed_query.years:
34-
CONSOLE.print(
35-
f"[red]No {indicator_name} Indicator Data in years: "
36-
f"{list(failed_query.years)}"
37-
)
38-
if failed_query.months:
39-
CONSOLE.print(
40-
f"[red]No {indicator_name} Indicator Data in months: "
41-
f"{list(failed_query.months)}"
42-
)
43-
if failed_query.year_months:
44-
CONSOLE.print(
45-
f"[red]No {indicator_name} Indicator Data in year_months: "
46-
f"{[f'{year_month[0]}-{year_month[1]:02}' for year_month in failed_query.year_months]}"
47-
)
48-
49-
5028
def print_trivial_indicator(
5129
indicator_name: str,
5230
indicator_data: "TrivialIndicatorData",

opendigger_pycli/console/utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import typing as t
22

3+
from . import CONSOLE
4+
35
if t.TYPE_CHECKING:
46
from opendigger_pycli.datatypes import NameAndValue, NameNameAndValue
7+
from opendigger_pycli.datatypes.query import IndicatorQuery
58

69

710
def if_prettey(value: t.Any) -> bool:
@@ -13,3 +16,26 @@ def if_prettey(value: t.Any) -> bool:
1316
value = t.cast(t.List["NameNameAndValue"], value)
1417
return True
1518
return False
19+
20+
21+
def print_failed_query(
22+
indicator_name: str, failed_query: t.Optional["IndicatorQuery"]
23+
) -> None:
24+
if failed_query is None:
25+
return
26+
27+
if failed_query.years:
28+
CONSOLE.print(
29+
f"[red]No {indicator_name} Indicator Data in years: "
30+
f"{list(failed_query.years)}"
31+
)
32+
if failed_query.months:
33+
CONSOLE.print(
34+
f"[red]No {indicator_name} Indicator Data in months: "
35+
f"{list(failed_query.months)}"
36+
)
37+
if failed_query.year_months:
38+
CONSOLE.print(
39+
f"[red]No {indicator_name} Indicator Data in year_months: "
40+
f"{[f'{year_month[0]}-{year_month[1]:02}' for year_month in failed_query.year_months]}"
41+
)

0 commit comments

Comments
 (0)