Skip to content

Instantly share code, notes, and snippets.

@0x46616c6b
Created September 10, 2013 06:18
Show Gist options
  • Save 0x46616c6b/6505621 to your computer and use it in GitHub Desktop.
Save 0x46616c6b/6505621 to your computer and use it in GitHub Desktop.
<?php
require __DIR__ . '/vendor/autoload.php';
use Guzzle\Http\Client as HttpClient;
use Predis\Client as RedisClient;
$redis = new RedisClient();
$apiKey = '5P5SIaxS644YqeDbz6sFsT4ATJ2NkJhe';
$currentTimestamp = time();
$threshold = 60 * 60 * 24 * 30; // 30 days
$limitTimestamp = ($currentTimestamp - $threshold) * 1000;
$count = 0;
$pads = array();
foreach ($redis->keys('pad:*') as $pad) {
$padId = preg_replace('/pad:/', '', $pad);
$padId = substr(
$padId,
0,
strpos($padId, ':')
);
if (in_array($padId, $pads)) continue;
$pads[] = $padId;
}
echo count($pads) . "\n";
$client = new HttpClient('http://localhost:9001');
foreach ($pads as $padId) {
$request = $client->get(
sprintf(
'/api/1/getLastEdited?apikey=%s&padID=%s',
$apiKey,
$padId
)
);
$data = $request->send()->getBody();
$attr = json_decode($data, true);
if ($attr['code'] == 0) {
$lastEdited = $attr['data']['lastEdited'];
if (isset($lastEdited)) {
if ($lastEdited < $limitTimestamp) {
$request = $client->get(
sprintf(
'/api/1/deletePad?apikey=%s&padID=%s',
$apiKey,
$padId
)
);
$request->send();
echo $padId . " wurde gelöscht" . "\n";
echo "Letzte Benutzung: " . date('d.m.Y H:i', $lastEdited / 1000) . "\n\n";
$count++;
}
}
}
}
echo $count . " Pads wurden gelöscht!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment