Skip to content

Commit

Permalink
Split get_dojo_list script into .rb and .txt files #1433
Browse files Browse the repository at this point in the history
  • Loading branch information
yasulab committed May 18, 2022
1 parent 39a4e92 commit 1f37e74
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
20 changes: 0 additions & 20 deletions get_dojo_linked_text.rb

This file was deleted.

33 changes: 33 additions & 0 deletions get_dojo_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

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

# Google Spreadsheet などから対象となった Dojo 名の列をコピーし、
# get_dojo_list.txt にペースト後、本スクリプトを実行すると、
# お知らせ記事などで使える HTML のリスト一覧が出力されます。
#
# 詳細: https://github.com/coderdojo-japan/coderdojo.jp/pull/1433

TEXT = IO.readlines('./get_dojo_list.txt')
DOJOS = JSON.parse(Net::HTTP.get URI.parse('https://coderdojo.jp/dojos.json'))
result = "<ul>\n"

# CoderDojo の名前を使って、Dojo 一覧からデータを検索
dojo_name =''
not_found = []
TEXT.each do |line|
next if line.start_with?('#') || line.strip.empty?
dojo_name = line.split[1..].join
dojo_data = DOJOS.find {|dojo| dojo['name'].start_with? dojo_name}
not_found << dojo_name && next if dojo_data.nil?
result << " <li>#{dojo_data['linked_text']}</li>\n"
#result << " <li>#{d['linked_text']}</li>\n"
end
result << "</ul>\n"
puts result

# 検索して見つからなかった Dojo 一覧があれば出力
puts '---' if not_found.nil?
not_found.each {|dojo_name| puts "Not found: #{dojo_name}" }
11 changes: 11 additions & 0 deletions get_dojo_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Google Spreadsheet などから対象となった Dojo 名の列をコピーし、
# 本 TXT ファイルの以下にペースト後、get_dojo_list.rb を実行すると、
# お知らせ記事などで使える HTML のリスト一覧が出力されます。
#
# 詳細: https://github.com/coderdojo-japan/coderdojo.jp/pull/1433

CoderDojo 札幌
CoderDojo 札幌東
CoderDojo 室蘭
CoderDojo 八戸
CoderDojo 陸前高田

0 comments on commit 1f37e74

Please sign in to comment.