-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.php
46 lines (38 loc) · 1.2 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// Load the composer autloader
require __DIR__ . '/vendor/autoload.php';
// Load the Dotenv package
use Symfony\Component\Dotenv\Dotenv;
// Read the environment variables
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env.local');
// Prep the DSN and options for PDO
$dsn = "mysql:host=".$_ENV['DB_HOST'].";dbname=".$_ENV['DB_NAME'].";charset=utf8";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
// Open up a PDO connection to your database
try {
$pdo = new PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASS'], $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
function parse(array $list): array
{
$output = [];
foreach ($list as &$object) {
$guildData = json_decode($object['data']);
calcAge($guildData);
$output[$object['id']] = $guildData;
}
return $output;
}
function calcAge(object $guildData)
{
$start = new DateTime('@' . round($guildData->creationDate / 1000));
$end = DateTime::createFromFormat('U.u', microtime(true));
$interval = $end->diff($start);
$guildData->age = $interval->days;
}