Skip to content

Instantly share code, notes, and snippets.

@tmd45
Created August 22, 2017 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmd45/7f6e49acbc35937b50de25a5886622b0 to your computer and use it in GitHub Desktop.
Save tmd45/7f6e49acbc35937b50de25a5886622b0 to your computer and use it in GitHub Desktop.
Separate GCP billing by project
require 'rake'
require 'csv'
#
# Usage:
#
# Need files(.csv) in same folder "junk".
#
# $ ruby junk/classify_gcp_payments.rb project-name
#
project = ARGV[0]
p project
file_list = FileList.new('junk/account_activities_*.csv')
regexp_filename = /^junk\/account_activities_(.*)\.csv$/
csv_opt = {
headers: true,
return_headers: false
}
results = {}
file_list.each do |filename|
term = regexp_filename.match(filename).to_a[1] # filename から YYYYMM を取得
amounts = []
CSV.foreach(filename, "r:bom|utf-8") do |row|
next unless row[0] == 'COSTS'
next unless row[1].include? project
amounts << row[2].to_f
end
results[term] = amounts.inject(:+).round(2)
end
p results.keys
p results.values
@tmd45
Copy link
Author

tmd45 commented Aug 22, 2017

console.cloud.google.com/billing からダウンロードした CSV ファイルから、特定の project の料金だけ集計したいやつ

@tmd45
Copy link
Author

tmd45 commented Sep 5, 2017

表示によってエクスポートできるCSV形式がことなるので注意 😱

feedfor____

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment