-
-
Notifications
You must be signed in to change notification settings - Fork 108
Static yaml generator for kodaira #251
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# For Kodaira's dojo event histories | ||
# | ||
# Google spread sheet url | ||
# https://docs.google.com/spreadsheets/d/15oTUF20IBQ99taJb3BO10Xpbn0tR-c_xmTJQUwH2M38/edit#gid=1633991574 | ||
# | ||
# google-drive-ruby(for Google API) | ||
# https://github.com/gimite/google-drive-ruby/blob/bc8d27b1c4f7369bba6e308525377444c3932364/doc/authorization.md#on-behalf-of-you-command-line-authorization | ||
|
||
SPREAD_SHEET_KEY = '15oTUF20IBQ99taJb3BO10Xpbn0tR-c_xmTJQUwH2M38'.freeze | ||
WORK_SHEET_NAME = '参加'.freeze | ||
KODAIRA_DOJO_ID = 13 | ||
|
||
def col_index(str) | ||
col = 0 | ||
str.upcase.each_byte do |b| | ||
col = col * 26 + (b - 0x41) # 0x41: 'A' | ||
end | ||
col | ||
end | ||
|
||
if ARGV.empty? | ||
puts 'Usage: bin/rails r scripts/kodaira_ss.rb CONFIG_JSON_FILE' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好みの問題かもしれないませんが、 |
||
puts | ||
puts 'Require the json file of configurations for Google API' | ||
puts 'see: https://github.com/gimite/google-drive-ruby/blob/bc8d27b1c4f7369bba6e308525377444c3932364/doc/authorization.md#on-behalf-of-you-command-line-authorization' | ||
exit 1 | ||
end | ||
|
||
puts 'CoderDojo小平の統計情報スプレッドシートを解析します' | ||
|
||
conf = File.expand_path(ARGV[0]) | ||
session = GoogleDrive::Session.from_config(conf) | ||
ss = session.spreadsheet_by_key(SPREAD_SHEET_KEY) | ||
ws = ss.worksheets.find { |s| s.title == WORK_SHEET_NAME } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. あー、でも ss を sheet にしちゃうと ws も sheet になっちゃうのか 💦 |
||
|
||
# A:通番, C:日付, G:時間, K:合計参加者 | ||
res = ws.rows.each.with_object([]) do |row, arr| | ||
serial_number = Integer(row[col_index('A')]) rescue nil | ||
next unless serial_number | ||
next unless arr.length == serial_number - 1 | ||
|
||
arr << { | ||
'dojo_id' => KODAIRA_DOJO_ID, | ||
'evented_at' => "#{row[col_index('C')]} #{row[col_index('G')].split('-').first}", | ||
'participants' => row[col_index('K')].to_i | ||
} | ||
end | ||
|
||
output = File.open("tmp/kodaira_histories_#{Time.zone.now.strftime('%Y%m%d%H%M%S')}.yml", 'w') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yamlファイルを上書きする方向で運用するのであれば、 |
||
YAML.dump(res, output) | ||
|
||
puts "#{output.path}にCoderDojo小平のEventHistoryのデータソースを書き出しました" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
便利メソッドですね! 😸 #228 でも活用できそう🤔💭