From 07dc74d9e73585d840854c642523f0fc05075df8 Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 25 Nov 2024 23:24:26 +0100 Subject: Fuck off, Zuck --- providers/Facebook.php | 18 +++++++++++++++++- providers/Provider.php | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'providers') diff --git a/providers/Facebook.php b/providers/Facebook.php index 20f5028..384c013 100644 --- a/providers/Facebook.php +++ b/providers/Facebook.php @@ -26,7 +26,23 @@ class Facebook extends \Providers\Provider { implode(DIRECTORY_SEPARATOR, [dirname(__FILE__), '..', 'bin', 'fb-scrape']) . ' ' . 'python ' . implode(DIRECTORY_SEPARATOR, [dirname(__FILE__), '..', 'bin', 'fb-scrape', 'get-fb-content.py']) . ' ' . escapeshellarg($this->_feed), $jsonContent); - return json_decode(implode(PHP_EOL, $jsonContent), TRUE); + $cacheFile = sprintf($this->_getCachePath(), $this->_feed); + if (file_exists($cacheFile)) { + $cache = unserialize($this->_getCache($cacheFile)); + } + else { + $cache = []; + } + $fetched = json_decode(implode(PHP_EOL, $jsonContent), TRUE); + $cacheIDs = array_map(function($obj) { + return $obj['id']; + }, $cache); + foreach ($fetched as $fetchedItem) { + if (!in_array($fetchedItem['id'], $cacheIDs)) { + $cache[] = $fetchedItem; + } + } + return $cache; } protected function _mapItems($content) { diff --git a/providers/Provider.php b/providers/Provider.php index 434b1d1..7e7dbf0 100644 --- a/providers/Provider.php +++ b/providers/Provider.php @@ -35,6 +35,9 @@ abstract class Provider { return unserialize($this->_getCache($cacheFile)); } else { $content = $this->_fetchItems(); + if (empty($content) && file_exists($cacheFile)) { + return unserialize($this->_getCache($cacheFile)); + } file_put_contents($cacheFile, serialize($content)); $this->_cacheTime = time(); return $content; -- cgit v1.2.3