pca/pca.php
2025-05-15 14:25:39 +02:00

38 lines
1.3 KiB
PHP

<?php
$filename = 'pca.json';
if (file_exists($filename) && (time()-720 < filemtime($filename))) {
echo file_get_contents($filename);
} else {
output_pca($filename);
}
function output_pca($filename) {
$html = file_get_contents('https://wiki.pnut.io/PCA');
$doc = new DOMDocument();
$doc->loadHTML($html);
$tables = $doc->getElementsByTagName('table');
$pca = array();
foreach ($tables as $table) {
if ($table->hasAttribute('class') && $table->getAttribute('class') == 'wikitable') {
foreach ($table->getElementsByTagName('tr') as $childNode) {
$entry = $childNode->getElementsByTagName('td');
if ($entry->length > 0) {
$achievement["pca"] = preg_replace('/\s+/', '', $entry->item(0)->textContent);
$achievement["emoji"] = preg_replace('/\s+/', '', $entry->item(1)->textContent);
$achievement["post_count"] = preg_replace('/\s+/', '', $entry->item(2)->textContent);
$achievement["inventor"] = preg_replace('/\s+/', '', $entry->item(3)->textContent);
$pca[] = $achievement;
}
}
}
}
$myfile = fopen($filename, "w");
$file_content = json_encode($pca);
fwrite($myfile, $file_content);
fclose($myfile);
echo $file_content;
}
?>