diff options
author | emkael <emkael@tlen.pl> | 2020-11-07 02:18:23 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-11-07 02:18:23 +0100 |
commit | c04e31020120b9dbec370691e793618e7425f675 (patch) | |
tree | a3a27021b0464912c36b91e7b1f1e166f6a99d58 /providers/Facebook.php | |
parent | dfcc897435102033ef9038e1ff3f1f44e981387b (diff) |
Jeb się, cukiergóra
Diffstat (limited to 'providers/Facebook.php')
-rw-r--r-- | providers/Facebook.php | 36 |
1 files changed, 25 insertions, 11 deletions
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 ]; |