From c04e31020120b9dbec370691e793618e7425f675 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 7 Nov 2020 02:18:23 +0100 Subject: Jeb się, cukiergóra MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/Facebook.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'providers/Facebook.php') diff --git a/providers/Facebook.php b/providers/Facebook.php index de863fd..b3f2015 100644 --- a/providers/Facebook.php +++ b/providers/Facebook.php @@ -31,6 +31,21 @@ class Facebook extends \Providers\HtmlFeed { return sprintf('https://m.facebook.com/%s/posts', $feed); } + private function _extractTimestamp($block) { + $origString = (string)$block->find('abbr')->eq(0)->text(); + $string = str_replace("\xc2\xa0", ' ', $origString); + $string = str_replace(' godzinie ', ' ', $string); + $string = str_replace(' o ', ', ', $string); + $string = str_replace('godz.', 'hours ago', $string); + $string = str_replace('Wczoraj', 'Yesterday', $string); + $string = str_replace(['stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia'], ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], $string); + $time = strtotime($string); + if (!$time) { + throw new Exception('Cannot parse date string: ' . $origString); + } + return $string; + } + protected function _parseFeedContent($tree) { $items = []; if (isset($this->_options['dump'])) { @@ -38,18 +53,17 @@ class Facebook extends \Providers\HtmlFeed { } foreach ($tree->find('#timelineBody div[data-ft]') as $header) { $data = json_decode($header->attr()['data-ft'], TRUE); - if (isset($data['page_insights'])) { - $data = $data['page_insights']; - $data = array_filter( - $data, - function($a) { return isset($a['post_context']); } - ); - $data = array_pop($data); - $data = $data['post_context']; - $key = ((array)($data['story_fbid']))[0]; + if (isset($this->_options['dump'])) { + var_dump($data); + } + if (isset($data['mf_story_key'])) { + $key = $data['mf_story_key']; $texts = []; foreach ($header->find('p, h3') as $paragraph) { - $texts[] = $paragraph->text(); + $text = $paragraph->text(); + if ($text != 'Więcej') { + $texts[] = $text; + } } if (isset($this->_options['dump'])) { print_r($data); @@ -61,7 +75,7 @@ class Facebook extends \Providers\HtmlFeed { if (count($texts)) { $items[$key] = [ 'id' => $key, - 'time' => $data['publish_time'], + 'time' => $this->_extractTimestamp($header), 'content' => $header->html(), 'texts' => $texts ]; -- cgit v1.2.3