Skip to content

Commit 75aa3ed

Browse files
committed
✨ DojoCast ポッドキャスト RSS を news:fetch タスクに追加
- DOJO_CAST_FEED として https://coderdojo.jp/podcasts.rss を追加 - fetch_podcast_posts() メソッドを実装(RSS 2.0 形式対応) - 本番環境で DojoCast の新着エピソードも「新着情報」として取得可能に
1 parent 0d164ef commit 75aa3ed

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/tasks/news.rake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ TEST_NEWS_FEED = Rails.root.join('spec', 'fixtures', 'sample_news.rss').freeze
66
DOJO_NEWS_FEED = 'https://news.coderdojo.jp/feed/'.freeze
77
DOJO_NEWS_JSON = 'https://news.coderdojo.jp/wp-json/wp/v2/posts'.freeze
88
PR_TIMES_FEED = 'https://prtimes.jp/companyrdf.php?company_id=38935'.freeze
9+
DOJO_CAST_FEED = 'https://coderdojo.jp/podcasts.rss'.freeze
910

1011
NEWS_YAML_PATH = 'db/news.yml'.freeze
1112
NEWS_LOGS_PATH = 'log/news.log'.freeze
@@ -61,6 +62,18 @@ def fetch_prtimes_posts(rss_feed_url)
6162
end
6263
end
6364

65+
# DojoCast ポッドキャスト RSS フィードから取得するメソッド
66+
def fetch_podcast_posts(rss_feed_url)
67+
feed = RSS::Parser.parse(rss_feed_url, false)
68+
feed.items.map do |item|
69+
{
70+
'url' => item.link,
71+
'title' => item.title,
72+
'published_at' => item.pubDate.in_time_zone('Asia/Tokyo').iso8601
73+
}
74+
end
75+
end
76+
6477
namespace :news do
6578
desc "ニュースフィードを取得し、#{NEWS_YAML_PATH} を再構築(冪等)"
6679
task fetch: :environment do
@@ -83,14 +96,17 @@ namespace :news do
8396
}
8497
}
8598
else
86-
# 本番環境: WordPress REST API + PR TIMES RSS
99+
# 本番環境: WordPress REST API + PR TIMES RSS + Podcast RSS
87100
dojo_news_items = fetch_dojo_news_posts(DOJO_NEWS_JSON)
88101
TASK_LOGGER.info("📰 news.coderdojo.jp から #{dojo_news_items.size} 件を取得")
89102

90103
prtimes_items = fetch_prtimes_posts(PR_TIMES_FEED)
91104
TASK_LOGGER.info("📢 PR TIMES から #{prtimes_items.size} 件を取得")
92105

93-
items = dojo_news_items + prtimes_items
106+
podcast_items = fetch_podcast_posts(DOJO_CAST_FEED)
107+
TASK_LOGGER.info("🎙️ DojoCast から #{podcast_items.size} 件を取得")
108+
109+
items = dojo_news_items + prtimes_items + podcast_items
94110
end
95111

96112
# 3. 古い順にソートして ID を付与(ISO 8601 なら文字列のままソート可能)

0 commit comments

Comments
 (0)