diff options
author | emkael <emkael@tlen.pl> | 2019-01-31 17:43:53 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-01-31 19:41:51 +0100 |
commit | 655d72e6f9a2bfdeef91e511728828eea44b62cc (patch) | |
tree | c5911e39315ca9fc86d592a3d501336844661999 /providers/Untappd.php | |
parent | fe23a611b9479723c6c654c3fe4daba9e870cf0c (diff) |
Untappd provider
Diffstat (limited to 'providers/Untappd.php')
-rw-r--r-- | providers/Untappd.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/providers/Untappd.php b/providers/Untappd.php new file mode 100644 index 0000000..95c7ab7 --- /dev/null +++ b/providers/Untappd.php @@ -0,0 +1,66 @@ +<?php + +namespace Providers; + +require_once('HtmlFeed.php'); +require_once('Item.php'); + +class Untappd extends \Providers\HtmlFeed { + + protected $_cacheTimeout = '5 minutes'; + + protected function _getCachePath() { + return '../cache/untappd.%s'; + } + + protected function _getFeedUrl($feed) { + return sprintf('https://untappd.com/%s/beer?sort=created_at_desc', $feed); + } + + protected function _parseFeedContent($tree) { + $items = []; + $parents = []; + foreach ($tree->find('div.beer-item') as $div) { + $details = $div->find('div.beer-details, div.details'); + if ($details) { + $texts = [ + $details->find('p.name')->text(), + $details->find('p.style')->text(), + $details->find('p.desc')->eq(1)->text(), + $details->find('p.abv')->text(), + $details->find('p.ibu')->text() + ]; + $items[] = [ + 'id' => $div->attr()['data-bid'], + 'link' => $div->find('a.label')->attr()['href'], + 'name' => $texts[0], + 'texts' => $texts, + 'time' => trim($details->find('p.date')->text()) + ]; + } + } + return array_values($items); + } + + protected function _mapItems($content) { + return array_map( + function ($obj) { + $item = new Item(); + $item->ID = $obj['id']; + $item->Link = sprintf('https://untappd.com/%s', $obj['link']); + $item->Title = sprintf('New beer by %s: %s', $this->_feed, $obj['name']); + $item->Text = implode('<br />', $obj['texts']); + $item->Time = strtotime(str_replace('Added ', '', $obj['time']) . ' 00:00:00'); + return $item; + }, + $content + ); + } + + public function title() { + return sprintf("%s's untappd beer list", $this->_feed); + } + +} + +?> |