diff --git a/Gemfile b/Gemfile index ce08fc84d..9f5559b79 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,8 @@ gem 'rack-user_agent' gem 'rack-attack' +gem 'google_drive' + group :development do gem 'web-console' gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 12d179882..982b4cdd0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,6 +73,8 @@ GEM connection_pool (2.2.1) crass (1.0.2) debug_inspector (0.0.3) + declarative (0.0.10) + declarative-option (0.1.0) diff-lcs (1.3) erubi (1.7.0) erubis (2.7.0) @@ -95,6 +97,25 @@ GEM net-http-pipeline globalid (0.4.1) activesupport (>= 4.2.0) + google-api-client (0.13.6) + addressable (~> 2.5, >= 2.5.1) + googleauth (~> 0.5) + httpclient (>= 2.8.1, < 3.0) + mime-types (~> 3.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.0) + google_drive (2.1.8) + google-api-client (>= 0.11.0, < 0.14.0) + googleauth (>= 0.5.0, < 1.0.0) + nokogiri (>= 1.5.3, < 2.0.0) + googleauth (0.5.1) + faraday (~> 0.9) + jwt (~> 1.4) + logging (~> 2.0) + memoist (~> 0.12) + multi_json (~> 1.11) + os (~> 0.9) + signet (~> 0.7) haml (5.0.4) temple (>= 0.8.0) tilt @@ -110,6 +131,7 @@ GEM haml (>= 4.0, < 6) nokogiri (>= 1.6.0) ruby_parser (~> 3.5) + httpclient (2.8.3) hyp_diff (0.0.5) diff-lcs (~> 1.2, >= 1.2.5) nokogiri (~> 1.6, >= 1.6.5) @@ -125,6 +147,7 @@ GEM jquery-ui-rails (6.0.1) railties (>= 3.2.16) json (2.1.0) + jwt (1.5.6) koala (3.0.0) addressable faraday @@ -136,6 +159,10 @@ GEM rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) + little-plugger (1.1.4) + logging (2.2.2) + little-plugger (~> 1.1) + multi_json (~> 1.10) loofah (2.1.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -159,6 +186,7 @@ GEM nio4r (2.1.0) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) + os (0.9.6) pg (0.21.0) pry (0.11.2) coderay (~> 1.1.0) @@ -219,6 +247,11 @@ GEM rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) + representable (3.0.4) + declarative (< 0.1.0) + declarative-option (< 0.2.0) + uber (< 0.2.0) + retriable (3.1.1) rspec-core (3.7.0) rspec-support (~> 3.7.0) rspec-expectations (3.7.0) @@ -291,6 +324,11 @@ GEM childprocess (~> 0.5) rubyzip (~> 1.0) sexp_processor (4.10.0) + signet (0.8.1) + addressable (~> 2.3) + faraday (~> 0.9) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) simple_grid_rails (0.1.0) spring (2.0.2) activesupport (>= 4.2) @@ -319,6 +357,7 @@ GEM ethon (>= 0.8.0) tzinfo (1.2.4) thread_safe (~> 0.1) + uber (0.1.0) uglifier (3.2.0) execjs (>= 0.3.0, < 3) useragent (0.16.8) @@ -346,6 +385,7 @@ DEPENDENCIES faraday faraday_middleware (= 0.10) font-awesome-rails + google_drive haml-rails jbuilder jquery-rails diff --git a/scripts/kodaira_ss.rb b/scripts/kodaira_ss.rb new file mode 100644 index 000000000..a98ba7dcb --- /dev/null +++ b/scripts/kodaira_ss.rb @@ -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' + 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 } + +# 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') +YAML.dump(res, output) + +puts "#{output.path}にCoderDojo小平のEventHistoryのデータソースを書き出しました"