Skip to content

Instantly share code, notes, and snippets.

@iansltx
Last active September 23, 2016 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iansltx/3ddc62e56aca203cd54c703f27b5c014 to your computer and use it in GitHub Desktop.
Save iansltx/3ddc62e56aca203cd54c703f27b5c014 to your computer and use it in GitHub Desktop.
Ting CSV parser
<?php
if ($argc < 4) {
die("Usage: php ting.php minutesXXX.csv messagesXXX.csv megabytesXXX.csv\n");
}
$people = [];
$voice = fopen($argv[1], 'r');
$sms = fopen($argv[2], 'r');
$data = fopen($argv[3], 'r');
fgetcsv($voice);
fgetcsv($sms);
fgetcsv($data);
while ($row = fgetcsv($voice)) {
@$people[$row[4]]['Min'] += $row[11];
}
while ($row = fgetcsv($sms)) {
@$people[$row[3]]['SMS']++;
}
while ($row = fgetcsv($data)) {
@$people[$row[2]]['MB'] += $row[4] / 1000;
}
foreach ($people as $name => $stats) {
echo $name . ': ' . ($stats['Min'] ?? 0) . ' minutes, ' . ($stats['SMS'] ?? 0) . ' texts, ' .
round($stats['MB'] ?? 0) . "MB\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment