summaryrefslogtreecommitdiff
path: root/providers
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2024-11-25 23:24:26 +0100
committeremkael <emkael@tlen.pl>2024-11-25 23:24:26 +0100
commit07dc74d9e73585d840854c642523f0fc05075df8 (patch)
treea76bf82f6faee22a57bd6834595894161c98700c /providers
parent373141ac8765c76f06c496a51b320852447c20ba (diff)
Fuck off, Zuck
Diffstat (limited to 'providers')
-rw-r--r--providers/Facebook.php18
-rw-r--r--providers/Provider.php3
2 files changed, 20 insertions, 1 deletions
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;