Created
May 5, 2010 14:43
-
-
Save jonmagic/390860 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # setup my filenames | |
| sent_filename = ARGV[0] | |
| billed_filename = ARGV[1] | |
| to_bill_filename = sent_filename.split('.')[0]+'_send_again.csv' | |
| # create my arrays | |
| sent_array = [] | |
| File.open(sent_filename, 'r').each_line { |line| sent_array << line } | |
| return_array = [] | |
| File.open(billed_filename, 'r').each_line { |line| return_array << line } | |
| billed_array = [] | |
| to_bill_array = [] | |
| # compare sent and billed and create new array of who was billed | |
| sent_array[1..-1].each do |transaction| # I skip the first line because its auth info | |
| if transaction != nil # make sure we don't include a blank line | |
| transaction_parts = transaction.split(',') # split the transaction line into its parts | |
| transaction_id = transaction_parts[16].to_i # part 16 has our unique id, and an integer | |
| return_array.each do |return_item| # loop thru the returns | |
| return_id = return_item.split(',')[4].to_i # split the return item into its parts | |
| if return_id == transaction_id # compare the return id with transaction id | |
| billed_array << transaction # add transaction to billed array | |
| end | |
| end | |
| end | |
| end | |
| # create output file minus the intersection of the sent_array and billed_array | |
| output = File.open(to_bill_filename, "w") | |
| output << (( sent_array | billed_array ) - ( sent_array & billed_array )) | |
| output.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment