Last active
December 15, 2015 10:09
-
-
Save akirk/5243828 to your computer and use it in GitHub Desktop.
Petitionsunterschriften Wien
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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