Skip to content

Instantly share code, notes, and snippets.

@akirk
Last active December 15, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirk/5243828 to your computer and use it in GitHub Desktop.
Save akirk/5243828 to your computer and use it in GitHub Desktop.
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