From 31bdf7390a32e7f26955540092ea8cea8b4c104b Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Fri, 5 Aug 2016 13:16:00 +0200 Subject: [PATCH 1/2] [Castorus] Add new bridge --- bridges/CastorusBridge.php | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 bridges/CastorusBridge.php diff --git a/bridges/CastorusBridge.php b/bridges/CastorusBridge.php new file mode 100644 index 0000000..d54bb5b --- /dev/null +++ b/bridges/CastorusBridge.php @@ -0,0 +1,92 @@ +maintainer = "logmanoriginal"; + $this->name = "Castorus Bridge"; + $this->uri = $this->getURI(); + $this->description = "Returns the latest changes"; + $this->update = "2016-08-05"; + } + + // Extracts the tile from an actitiy + function ExtractActivityTitle($activity){ + $title = $activity->find('a', 0); + + if(!$title) + $this->returnError('Cannot find title!', 404); + + return htmlspecialchars(trim($title->plaintext)); + } + + // Extracts the url from an actitiy + function ExtractActivityUrl($activity){ + $url = $activity->find('a', 0); + + if(!$url) + $this->returnError('Cannot find url!', 404); + + return $this->getURI() . $url->href; + } + + // Extracts the time from an activity + function ExtractActivityTime($activity){ + // Unfortunately the time is part of the parent node, + // so we have to clear all child nodes first + $nodes = $activity->find('*'); + + if(!$nodes) + $this->returnError('Cannot find nodes!', 404); + + foreach($nodes as $node){ + $node->outertext = ''; + } + + return strtotime($activity->innertext); + } + + // Extracts the price change + function ExtractActivityPrice($activity){ + $price = $activity->find('span', 1); + + if(!$price) + $this->returnError('Cannot find price!', 404); + + return $price->innertext; + } + + public function collectData(array $params){ + $html = $this->file_get_html($this->getURI()); + + if(!$html) + $this->returnError('Could not load data from ' . $this->getURI() . '!', 404); + + $activities = $html->find('div#activite/li'); + + if(!$activities) + $this->returnError('Failed to find activities!', 404); + + foreach($activities as $activity){ + $item = new \Item(); + + $item->title = $this->ExtractActivityTitle($activity); + $item->uri = $this->ExtractActivityUrl($activity); + $item->timestamp = $this->ExtractActivityTime($activity); + $item->content = '' . $item->title . '

' + . $this->ExtractActivityPrice($activity) . '

'; + + $this->items[] = $item; + } + } + + public function getName(){ + return 'Castorus Bridge'; + } + + public function getURI(){ + return 'http://www.castorus.com'; + } + + public function getCacheDuration(){ + return 3600; // 1 hour + } +} From e4a56e504e9166cbea98c7c6456458da3437e043 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Fri, 5 Aug 2016 13:19:36 +0200 Subject: [PATCH 2/2] [Castorus] Reduce cache duration to 10 minutes --- bridges/CastorusBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/CastorusBridge.php b/bridges/CastorusBridge.php index d54bb5b..69d8961 100644 --- a/bridges/CastorusBridge.php +++ b/bridges/CastorusBridge.php @@ -87,6 +87,6 @@ class CastorusBridge extends BridgeAbstract { } public function getCacheDuration(){ - return 3600; // 1 hour + return 600; // 10 minutes } }