-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from WoongyuChoi/dev
Dev
- Loading branch information
Showing
6 changed files
with
110 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .external import * | ||
from .external import ExternalAPI | ||
|
||
__all__ = [name for name in globals() if not name.startswith("_")] | ||
__all__ = ["ExternalAPI"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from handler.logger import get_logger | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class DataProcessor: | ||
""" | ||
외부 API에서 받은 데이터를 처리하는 클래스. | ||
""" | ||
|
||
@staticmethod | ||
def process_exchange_rate_data(response_data): | ||
if "StatisticSearch" not in response_data: | ||
logger.error(f"ValueError: {str(response_data)}") | ||
|
||
raw_rows = response_data.get("StatisticSearch", {}).get("row", []) | ||
if not raw_rows: | ||
return {"content": []} | ||
|
||
processed_data = [] | ||
for row in raw_rows: | ||
try: | ||
value = float(row.get("DATA_VALUE", "0").replace(",", "")) | ||
except ValueError: | ||
value = 0 | ||
|
||
processed_data.append( | ||
{ | ||
"value": value, | ||
"item_code": row.get("ITEM_CODE1"), | ||
"item_name": row.get("ITEM_NAME1"), | ||
"time": row.get("TIME"), | ||
"unit": ( | ||
row.get("UNIT_NAME").strip() if row.get("UNIT_NAME") else None | ||
), | ||
} | ||
) | ||
|
||
sorted_data = sorted( | ||
processed_data, | ||
key=lambda x: x["time"] if x["time"] else "", | ||
reverse=False, | ||
) | ||
|
||
return {"content": sorted_data} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from .date_utils import get_first_day_of_last_month, get_last_day_of_last_month | ||
from .fetch_utils import fetch_data, generate_statistic_url | ||
from .request_utils import get_request_params | ||
|
||
__all__ = [ | ||
"get_first_day_of_last_month", | ||
"get_last_day_of_last_month", | ||
"fetch_data", | ||
"generate_statistic_url", | ||
"get_request_params", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask import request | ||
|
||
|
||
def get_request_params(*keys, defaults=None): | ||
""" | ||
요청에서 여러 파라미터를 한 번에 추출. | ||
:param keys: 추출할 파라미터 키들 | ||
:param defaults: 기본값 딕셔너리 (key-value 쌍) | ||
:return: 추출된 파라미터 딕셔너리 | ||
""" | ||
if defaults is None: | ||
defaults = {} | ||
|
||
return {key: request.args.get(key, defaults.get(key)) for key in keys} |