Skip to content

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

Merged
merged 4 commits into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ gem 'rack-user_agent'

gem 'rack-attack'

gem 'google_drive'

group :development do
gem 'web-console'
gem 'spring'
Expand Down
40 changes: 40 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -346,6 +385,7 @@ DEPENDENCIES
faraday
faraday_middleware (= 0.10)
font-awesome-rails
google_drive
haml-rails
jbuilder
jquery-rails
Expand Down
52 changes: 52 additions & 0 deletions scripts/kodaira_ss.rb
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

便利メソッドですね! 😸 #228 でも活用できそう🤔💭


if ARGV.empty?
puts 'Usage: bin/rails r scripts/kodaira_ss.rb CONFIG_JSON_FILE'
Copy link
Member

@yasulab yasulab Feb 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好みの問題かもしれないませんが、ss は Screen Shot や Same Size などの様々な略語も含んでいるので、sheet の方が判別が付きやすいかもしれないですね🤔

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 }
Copy link
Member

Choose a reason for hiding this comment

The 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yamlファイルを上書きする方向で運用するのであれば、%Y%m%dまで情報があれば十分かも?

YAML.dump(res, output)

puts "#{output.path}にCoderDojo小平のEventHistoryのデータソースを書き出しました"