Skip to content

Instantly share code, notes, and snippets.

@akirk akirk/gist:5243828
Last active Dec 15, 2015

Embed
What would you like to do?
Petitionsunterschriften Wien
<?php
echo getNumberOfPetitionSignatures("446def6e128c4f199ddfdce70c599775"), "\n";
// oder
echo getNumberOfPetitionSignaturesCached("446def6e128c4f199ddfdce70c599775"), "\n";
function getNumberOfPetitionSignaturesCached($id) {
// aktuelles Verzeichnis muss schreibbar sein, sonst Pfad ändern
$cache = __DIR__ . "/unterschriften-$id.txt";
// 300s = 5 minuten
if (file_exists($cache) && time() - filemtime($cache) < 300) return file_get_contents($cache);
file_put_contents($cache, $nr = getNumberOfPetitionSignatures($id));
return $nr;
}
function getNumberOfPetitionSignatures($id) {
$f = file_get_contents("https://www.wien.gv.at/petition/online/PetitionDetail.aspx?PetID=" . $id);
$p = strpos($f, "Anzahl bisheriger");
if ($p !== false) {
$p = strpos($f, ">", $p);
$q = strpos($f, "</tr", $p);
$txt = strip_tags(substr($f, $p, $q - $p));
if (preg_match("#[0-9]+#", $txt, $m)) {
return $m[0];
}
}
return "Unbekannt";
}
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.