Skip to content

Commit 1f37e74

Browse files
committed
Split get_dojo_list script into .rb and .txt files #1433
1 parent 39a4e92 commit 1f37e74

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

get_dojo_linked_text.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

get_dojo_list.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'net/http'
4+
require 'json'
5+
require 'pry'
6+
7+
# Google Spreadsheet などから対象となった Dojo 名の列をコピーし、
8+
# get_dojo_list.txt にペースト後、本スクリプトを実行すると、
9+
# お知らせ記事などで使える HTML のリスト一覧が出力されます。
10+
#
11+
# 詳細: https://github.com/coderdojo-japan/coderdojo.jp/pull/1433
12+
13+
TEXT = IO.readlines('./get_dojo_list.txt')
14+
DOJOS = JSON.parse(Net::HTTP.get URI.parse('https://coderdojo.jp/dojos.json'))
15+
result = "<ul>\n"
16+
17+
# CoderDojo の名前を使って、Dojo 一覧からデータを検索
18+
dojo_name =''
19+
not_found = []
20+
TEXT.each do |line|
21+
next if line.start_with?('#') || line.strip.empty?
22+
dojo_name = line.split[1..].join
23+
dojo_data = DOJOS.find {|dojo| dojo['name'].start_with? dojo_name}
24+
not_found << dojo_name && next if dojo_data.nil?
25+
result << " <li>#{dojo_data['linked_text']}</li>\n"
26+
#result << " <li>#{d['linked_text']}</li>\n"
27+
end
28+
result << "</ul>\n"
29+
puts result
30+
31+
# 検索して見つからなかった Dojo 一覧があれば出力
32+
puts '---' if not_found.nil?
33+
not_found.each {|dojo_name| puts "Not found: #{dojo_name}" }

get_dojo_list.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Google Spreadsheet などから対象となった Dojo 名の列をコピーし、
2+
# 本 TXT ファイルの以下にペースト後、get_dojo_list.rb を実行すると、
3+
# お知らせ記事などで使える HTML のリスト一覧が出力されます。
4+
#
5+
# 詳細: https://github.com/coderdojo-japan/coderdojo.jp/pull/1433
6+
7+
CoderDojo 札幌
8+
CoderDojo 札幌東
9+
CoderDojo 室蘭
10+
CoderDojo 八戸
11+
CoderDojo 陸前高田

0 commit comments

Comments
 (0)