Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Loop through each finance report and run it using my process_finance_report script, creating an invoice in FreeAgent.
#!/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
Owner

lukeredpath commented Nov 15, 2010

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.

Owner

lukeredpath commented Nov 15, 2010

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?

Owner

lukeredpath commented Nov 15, 2010

Blogged in more detail here.

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