Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/php
<?php
ini_set('memory_limit', '256M');
set_time_limit(0);
require_once('include/local.conf');
require_once(COMMON_INCLUDE_PATH . 'db_mysql.class.php');
$ymds = array(20130107, 20130108, 20130109, 20130110, 20130111, 20130112, 20130113, 20130114, 20130115, 20130116,
20130117, 20130118, 20130119, 20130120, 20130121, 20130122, 20130123, 20130124, 20130125, 20130126,
20130127, 20130128, 20130129, 20130130, 20130131, 20130201, 20130202, 20130203, 20130204, 20130205,
20130206);
$ymds = array(20130107);
$db = DB_Sql::get_instance('email_readonly_DB');
$db->connect();
$db->set_throw_on_error(true);
$f = fopen('/tmp/deltas', 'a+');
$i = 0;
foreach ($ymds as $ymd) {
echo "\nAnalyzing {$ymd}... ";
$sql = "select guid, email, creationDate from Strongmail.Success where ymd = $ymd";
$result = mysql_query($sql, $db->Link_ID);
if (!$result)
die(PHP_EOL . "No Results! {$sql}" . PHP_EOL);
$count = mysql_num_rows($result);
echo "\nFound {$count} successful emails...";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if (isset($row['guid'], $row['creationDate'], $row['email'])) {
$sql = "select time_stamp from FE_EmailRecord where email_to = '{$row['email']}' and guid = '{$row['guid']}'";
if ($inner_result = mysql_query($sql, $db->Link_ID)) {
$inner_row = mysql_fetch_array($inner_result, MYSQL_ASSOC);
fwrite($f, "{$row['guid']}, {$row['creationDate']}, {$inner_row['time_stamp']}\n");
}
}
progress(++$i, $count, 'Percent Complete: ');
usleep(5000);
}
usleep(20000);
echo "Done!" . PHP_EOL;
}
function progress ($step_x, $of_y, $label = '') {
static $first = true;
$p = number_format($step_x / $of_y * 100, 3) . '%';
$p = str_pad($p, 5, ' ', STR_PAD_LEFT);
if ($label)
$p = "{$label} {$p}";
if (!$first)
echo str_repeat("\010", strlen($p));
if ($step_x < $of_y)
echo $p;
else
echo str_repeat(' ', strlen($p)) . PHP_EOL;
$first = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.