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

Load .env file and improve error handling for station list #4

Merged
merged 2 commits into from
Nov 20, 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
7 changes: 5 additions & 2 deletions radiko_recorder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ def main(argv=None):
args = parser.parse_args(argv)

if args.station_list:
# 放送局リストを表示
_show_station_list(args.area_id)
try:
# 放送局リストを表示
_show_station_list(args.area_id)
except ValueError as e:
print(e)
return

# 必須引数のチェック
Expand Down
7 changes: 4 additions & 3 deletions radiko_recorder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from dotenv import load_dotenv

# 環境変数へ反映
load_dotenv()
# 現在のスクリプトのディレクトリから.envをロード
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)

RADIKO_AREA_ID = os.getenv('RADIKO_AREA_ID')
RADIKO_AREA_ID = os.getenv('RADIKO_AREA_ID', 'JP13') # デフォルト値として東京エリア(JP13)を指定
6 changes: 3 additions & 3 deletions test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down