-
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 #19 from WoongyuChoi/dev
Dev
- Loading branch information
Showing
11 changed files
with
115 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .external import * | ||
|
||
__all__ = [name for name in globals() if not name.startswith("_")] |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .param_defaults import default_params | ||
|
||
__all__ = ["default_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,12 @@ | ||
from functools import wraps | ||
from utils import get_first_day_of_last_month, get_last_day_of_last_month | ||
|
||
|
||
def default_params(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
kwargs["start_date"] = kwargs.get("start_date") or get_first_day_of_last_month() | ||
kwargs["end_date"] = kwargs.get("end_date") or get_last_day_of_last_month() | ||
return func(*args, **kwargs) | ||
|
||
return wrapper |
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,22 @@ | ||
from flask import jsonify | ||
from werkzeug.exceptions import HTTPException | ||
|
||
|
||
def register_exception_handlers(app): | ||
@app.errorhandler(ValueError) | ||
def handle_value_error(e): | ||
app.logger.error(f"ValueError: {str(e)}") | ||
return jsonify({"error": "Invalid input provided."}), 400 | ||
|
||
@app.errorhandler(HTTPException) | ||
def handle_http_exception(e): | ||
app.logger.error(f"HTTPException: {str(e)}") | ||
return ( | ||
jsonify({"error": "A server error occurred. Please try again later."}), | ||
e.code, | ||
) | ||
|
||
@app.errorhandler(Exception) | ||
def handle_generic_exception(e): | ||
app.logger.error(f"Unexpected error: {str(e)}") | ||
return jsonify({"error": "An unexpected error occurred."}), 500 |
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,3 @@ | ||
from .api_params import APIParams | ||
|
||
__all__ = ["APIParams"] |
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,19 @@ | ||
import os | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class APIParams: | ||
base_url: str = "https://ecos.bok.or.kr/api" | ||
service_name: Optional[str] = None | ||
api_key: str = os.getenv("ECOS_API_KEY") | ||
response_format: str = "json" | ||
language: str = "kr" | ||
start_count: int = 1 | ||
end_count: int = 10000 | ||
table_code: Optional[str] = None | ||
period: str = "D" | ||
start_date: Optional[str] = None | ||
end_date: Optional[str] = None | ||
item_code: Optional[str] = None |
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,9 @@ | ||
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 | ||
|
||
__all__ = [ | ||
"get_first_day_of_last_month", | ||
"get_last_day_of_last_month", | ||
"fetch_data", | ||
"generate_statistic_url", | ||
] |
File renamed without changes.
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