public

Loop through each finance report and run it using my process_finance_report script, creating an invoice in FreeAgent.

  • Download Gist
process_last_months_finance_reports.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env ruby
SECONDS_IN_DAY = (24*60*60)
REPORT_ROOT = File.expand_path("~/Documents/Business/Accounts/iTunes Finance Reports")
 
# I group US and WW on the same invoice as they are both in USD
INVOICE_GROUPS = [%w{AU}, %w{CA}, %w{GB}, %w{EU}, %w{US WW}, %w{JP}]
 
one_month_ago = Time.now - (30 * SECONDS_IN_DAY)
 
# My "fetch_finance_reports" script puts reports in a sub-dir e.g. 2010-09-Aug
Dir.chdir(File.join(REPORT_ROOT, one_month_ago.strftime("%Y-%m-%b"))) do
reports = Dir["*.txt"]
INVOICE_GROUPS.each do |invoice|
puts "* Processing invoices for regions: #{invoice.join(", ")}"
reports_for_invoice = invoice.map { |region| File.basename(reports.grep(/#{region}\.txt/).first) }
puts "process_finance_report #{reports_for_invoice.join(" ")}"
end
end

More about the scripts I use to fetch the reports from iTunes Connect and then process them by creating invoices using the FreeAgent API can be found in this blog post.

Removed the ActiveSupport dependency. I realize that the one_month_ago implementation will fail if you run this on the 31st of the month...so, don't do that, right?

Blogged in more detail here.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.