Skip to content

Instantly share code, notes, and snippets.

@Schrank
Created February 19, 2014 19:41
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 Schrank/9099959 to your computer and use it in GitHub Desktop.
Save Schrank/9099959 to your computer and use it in GitHub Desktop.
Alle Piratenpartei Umlaufbeschlüsse ziehen und in PDF umwandeln
<?php
namespace MyNamespaceForFunctions;
use FPDF;
require_once 'fpdf.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
function utf8_decode($string)
{
return iconv("UTF-8", "ISO-8859-1//TRANSLIT", $string);
}
echo "Hole Liste\n";
if (file_exists('beschluesse.html')) {
$beschluesse = file_get_contents('beschluesse.html');
} else {
$beschluesse = file_get_contents('http://wiki.piratenpartei.de/BE:Beschlussantrag_Umlaufbeschluss');
file_put_contents('beschluesse.html', $beschluesse);
}
preg_match_all('#<a href="/(BE:Beschlussantrag_Umlaufbeschluss.*?)" title=".*">.*</a>#', $beschluesse, $matches);
$todo = count($matches[1]);
$done = 0;
foreach ($matches[1] as $url) {
$beschluss = file_get_contents("http://wiki.piratenpartei.de/wiki//index.php?title=$url&action=edit");
echo "Hole Beschluss $url\n";
preg_match(
'#<textarea id="wpTextbox1" name="wpTextbox1" cols="80" rows="25" readonly="">(.*)</textarea>#ms', $beschluss,
$matches
);
$text = $matches[1];
preg_match('#== Diskussion / Protokoll ==(.*)#ms', $text, $matches);
$diskussion = isset($matches[1]) ? str_replace('&lt;', '<', $matches[1]) : '';
$diskussion = trim(strip_tags($diskussion));
$infos = array(
'Typ',
'Datum',
'Nummer',
'Titel',
'Text',
'Begründung',
'LiquidFeedback',
'Antragsteller',
'Dafür',
'Dagegen',
'Enthaltung',
'Ergebnis',
'Umsetzungsverantwortlich',
'Vertagt',
);
foreach ($infos as $info) {
preg_match("#\|$info ?= ?(.*?)\W(\||}})#s", $text, $matches);
$collected[$info] = isset($matches[1]) ? trim(str_replace('&lt;', '<', $matches[1])) : '';
}
$pdf = new FPDF();
$pdf->AddPage();
foreach ($infos as $info) {
$pdf->SetFont('Arial', 'B', 16);
$pdf->MultiCell(190, 10, utf8_decode($info));
$pdf->SetFont('Arial', '', 12);
$pdf->MultiCell(190, 8, strip_tags(utf8_decode($collected[$info])), 0, 'J');
}
if ($diskussion) {
$pdf->SetFont('Arial', 'B', 16);
$pdf->MultiCell(190, 10, 'Diskussion / Protokoll');
$pdf->SetFont('Arial', '', 12);
$pdf->MultiCell(190, 8, strip_tags(utf8_decode($diskussion)), 0, 'J');
}
echo "Schreibe pdf " . $collected['Nummer'] . "\n";
$pdf->Output('pdf/' . str_replace('/', '_', $collected['Nummer']) . '.pdf', 'F');
printf("TODO: %04d / %04d\n", ++$done, $todo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment