Roastmonday/fetch_mondays.php
2025-05-24 13:23:02 +02:00

25 lines
844 B
PHP

<?php
require __DIR__ . '/vendor/autoload.php';
echo 'Scanning for new themes' . PHP_EOL;
$config = include __DIR__ . '/config.php';
$internal_pics_dir = __DIR__ . $config['pics_dir'];
echo 'Pics dir: ' . realpath($internal_pics_dir) . '<br>' . PHP_EOL;
$app = new Phlaym\Roastmonday\Roastmonday($config, realpath($internal_pics_dir));
$app->authenticateServerToken();
$tm = $app->findThemeMondays();
echo 'Only checking the latest four mondays for new pictures<br>\n';
$tm = array_slice($tm, 0, 4);
foreach ($tm as $monday) {
$monday['id'] = $app->addTheme($monday['tag'], $monday['date']);
echo $monday['tag'] . ' with id ' . $monday['id'] . '<br>\n';
try {
$app->savePicturesForTheme($monday);
} catch (\Exception $e) {
echo 'Error saving pictures for ' . $monday['tag'] . ':' . $e->getMessage();
}
}