Skip to content

Commit

Permalink
Detect and alert if in-active dojo found in a get_dojo_list task
Browse files Browse the repository at this point in the history
  • Loading branch information
yasulab committed Dec 25, 2024
1 parent 0c5b8b8 commit 61086f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 11 additions & 10 deletions get_dojo_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'net/http'
require 'json'
require 'pry'

# Google Spreadsheet などから対象となった Dojo 名の列をコピーし、
# get_dojo_list.txt にペースト後、本スクリプトを実行すると、
Expand Down Expand Up @@ -39,10 +38,10 @@
.split('、').first # Ex: 東大阪、八尾
.strip

# Search dojo data by its KANJI name from DOJO_DB
dojo_data = DOJO_DB.find do |dojo|
binding.pry if dojo_name.nil?
dojo[:name].start_with? dojo_name.downcase
# Search dojo data by its KANJI name from DOJO_DB (including inactive dojos).
# MEMO: Use `.reverse` to find a latest dojo in case of overriding inactive dojo's name.
found_dojo = DOJO_DB.reverse.find do |dojo|
dojo[:name] == dojo_name.downcase
.gsub('ishigaki', '石垣')
.gsub('hitachinaka', 'ひたちなか')
.gsub('kodaira', 'こだいら')
Expand All @@ -56,23 +55,25 @@
.gsub('harumi', '晴海')
.gsub('町田', 'まちだ')
.gsub('小平', 'こだいら')
.gsub('八戸', '八戸@吹上')
.gsub('吉備岡山', '吉備')
.gsub('浦和@urawa minecraft club', '浦和@Urawa Minecraft Club')
end

dojo_data.nil? ?
not_found << dojo_name :
dojo_list << dojo_data
(found_dojo && found_dojo[:is_active]) ?
dojo_list << found_dojo :
not_found << dojo_name
end

dojo_list.sort_by!{ |dojo| dojo[:order] }
result << dojo_list.map{ |dojo| " <li><a href='#{dojo[:url]}'>#{dojo[:name]}</a><small>(#{dojo[:prefecture]})</small></li>" }.join("\n")
result << dojo_list.map{ |dojo| "#{dojo[:is_active]} <li><a href='#{dojo[:url]}'>#{dojo[:name]}</a><small>(#{dojo[:prefecture]})</small></li>" }.join("\n")
result << "\n</ul>\n"
puts result

#binding.irb
# 検索して見つからなかった Dojo 一覧があれば出力
if not_found.any?
puts '--- NOTE ---'
puts "道場数: #{dojo_list.count}"
not_found.each {|dojo_name| puts "Not found: #{dojo_name}" }
not_found.each {|dojo_name| puts "Not-found or In-active: #{dojo_name}" }
end
5 changes: 3 additions & 2 deletions get_dojo_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ CoderDojo 稲沢正明寺
CoderDojo岐阜
CoderDojo伊勢
CoderDojo なかもず
CoderDojo 奈良・生駒
CoderDojo 奈良
CoderDojo 生駒
CoderDojo南紀田辺
CoderDojo 淡路島
CoderDojo 鳥取
Expand All @@ -50,7 +51,7 @@ CoderDojo 富山
CoderDojoとなみ
CoderDojo Yabuki
CoderDojo仙台若林
CoderDojo徳島
CoderDojo登米
CoderDojo 山形
CoderDojo Tsuruoka (鶴岡)
CoderDojo 札幌
Expand Down

0 comments on commit 61086f9

Please sign in to comment.