Skip to content

Instantly share code, notes, and snippets.

@tjlytle
Created January 11, 2011 01:50
Show Gist options
  • Save tjlytle/773861 to your computer and use it in GitHub Desktop.
Save tjlytle/773861 to your computer and use it in GitHub Desktop.
Simple script to convert an oDesk export to Outright's expected format.
<?php
$in = fopen($argv[1], 'r');
$out = fopen('php://output', 'w');
$fields = fgetcsv($in);
$map['date'] = 'Date';
$map['description'] = 'Description';
$map['payee'] = 'Employer';
$map['amount'] = 'Amount';
$map['category'] = 'Type';
fputcsv($out, array_keys($map));
$typeFilter = array('withdrawal', 'credit', 'payment');
while($row = fgetcsv($in)){
$row = array_combine($fields, $row);
if(in_array(strtolower($row['Type']), $typeFilter)){
continue;
}
if('referral' == strtolower($row['Type'])){
$row['Employer'] = 'oDesk';
}
$row['Type'] = 'Sales';
$row['Date'] = date('m/d/Y' , strtotime($row['Date']));
$data = array();
foreach($map as $name => $field){
$data[] = $row[$field];
}
fputcsv($out, $data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment