Skip to content

Instantly share code, notes, and snippets.

@nikhgupta
Created November 14, 2018 08:06
Show Gist options
  • Save nikhgupta/837d5a1726e019b239c8fb3c8febd68e to your computer and use it in GitHub Desktop.
Save nikhgupta/837d5a1726e019b239c8fb3c8febd68e to your computer and use it in GitHub Desktop.
Convert Upwork Transaction History to format suitable for Zoho Books
#!/usr/bin/env ruby
# Script to convert upwork transaction history to a CSV
# format that Zoho Books does accept.
require 'csv'
require 'pry'
require 'time'
path = ARGV.first
csv = CSV.read(path, headers: true)
csv = csv.entries.map do |row|
row = row.to_h
row['Date'] = Time.parse(row['Date']).strftime("%Y-%m-%d")
row['Direction'] = row["Amount"].to_f > 0 ? "c" : "d"
row["Amount"] = row["Amount"].to_f.abs()
row
end
mod_csv = CSV.generate do |str|
str << csv.first.keys
csv.each do |x|
str << x.values
end
end
File.write(path, mod_csv)
puts "Generated modified CSV at: #{path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment