From 1f2b295bf356dc58c7368c98721f9d5d79dd628f Mon Sep 17 00:00:00 2001
From: Michael Bemmerl
Date: Thu, 24 Mar 2022 21:42:15 +0000
Subject: [PATCH] [BundestagParteispendenBridge] Add bridge to get the latest
donations (#1613)
---
bridges/BundestagParteispendenBridge.php | 89 ++++++++++++++++++++++++
1 file changed, 89 insertions(+)
create mode 100644 bridges/BundestagParteispendenBridge.php
diff --git a/bridges/BundestagParteispendenBridge.php b/bridges/BundestagParteispendenBridge.php
new file mode 100644
index 00000000..446e61c0
--- /dev/null
+++ b/bridges/BundestagParteispendenBridge.php
@@ -0,0 +1,89 @@
+Partei:
%s
+Spendenbetrag:
%s
+Spender:
%s
+Eingang der Spende:
%s
+TMPL;
+
+ public function getIcon()
+ {
+ return 'https://www.bundestag.de/static/appdata/includes/images/layout/favicon.ico';
+ }
+
+ public function collectData()
+ {
+ $ajaxUri = <<find('a', 0)
+ or returnServerError('Could not find the proper HTML element.');
+
+ $url = 'https://www.bundestag.de' . $firstAnchor->href;
+
+ // Get the actual page with the soft money donations
+ $html = getSimpleHTMLDOMCached($url, self::CACHE_TIMEOUT)
+ or returnServerError('Could not request ' . $url);
+
+ $rows = $html->find('table.table > tbody > tr')
+ or returnServerError('Could not find the proper HTML elements.');
+
+ foreach($rows as $row) {
+ $item = $this->generateItemFromRow($row);
+ if (is_array($item)) {
+ $item['uri'] = $url;
+ $this->items[] = $item;
+ }
+ }
+ }
+
+ private function generateItemFromRow(simple_html_dom_node $row)
+ {
+ // The row must have 5 columns. There are monthly header rows, which are ignored here.
+ if(count($row->children) != 5)
+ return null;
+
+ $item = array();
+
+ // | column | paragraph inside column
+ $party = $row->children[0]->children[0]->innertext;
+ $amount = $row->children[1]->children[0]->innertext . ' €';
+ $donor = $row->children[2]->children[0]->innertext;
+ $date = $row->children[3]->children[0]->innertext;
+ $dip = $row->children[4]->children[0]->find('a.dipLink', 0);
+
+ // Strip whitespace from date string.
+ $date = str_replace(' ', '', $date);
+
+ $content = sprintf(self::CONTENT_TEMPLATE, $party, $amount, $donor, $date);
+
+ $item = array(
+ 'title' => $party . ': ' . $amount,
+ 'content' => $content,
+ 'uid' => sha1($content),
+ );
+
+ // Try to get the link to the official document
+ if ($dip != null)
+ $item['enclosures'] = array($dip->href);
+
+ // Try to parse the date
+ $dateTime = DateTime::createFromFormat('d.m.Y', $date);
+ if ($dateTime !== FALSE)
+ $item['timestamp'] = $dateTime->getTimestamp();
+
+ return $item;
+ }
+}