aboutsummaryrefslogtreecommitdiff
path: root/bridges/OllamaBridge.php
diff options
context:
space:
mode:
authorGravatar Anshul Gupta <ansg191@anshulg.com> 2025-03-02 19:32:33 -0800
committerGravatar GitHub <noreply@github.com> 2025-03-02 19:32:33 -0800
commit8b16dd20f6544af3eedf286e23c0d34ab525736c (patch)
treeec284e22a046c4c8e9626e3fa64a000a2747bf84 /bridges/OllamaBridge.php
parentb183aa798af48af556496c42780d6e844172cf44 (diff)
parent00a24e2f694a319a5e6cb070dddfff2dae892378 (diff)
downloadrss-bridge-master.tar.gz
rss-bridge-master.tar.zst
rss-bridge-master.zip
Merge branch 'RSS-Bridge:master' into masterHEADmaster
Diffstat (limited to 'bridges/OllamaBridge.php')
-rw-r--r--bridges/OllamaBridge.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/bridges/OllamaBridge.php b/bridges/OllamaBridge.php
new file mode 100644
index 00000000..f93e37ce
--- /dev/null
+++ b/bridges/OllamaBridge.php
@@ -0,0 +1,61 @@
+<?php
+
+class OllamaBridge extends BridgeAbstract
+{
+ const MAINTAINER = 'sqrtminusone';
+ const NAME = 'Ollama Blog Bridge';
+ const URI = 'https://ollama.com';
+
+ const CACHE_TIMEOUT = 3600; // 1 hour
+ const DESCRIPTION = 'Returns latest blog posts from Ollama';
+
+ const PARAMETERS = [
+ '' => [
+ 'limit' => [
+ 'name' => 'Limit',
+ 'type' => 'number',
+ 'required' => true,
+ 'defaultValue' => 10
+ ],
+ ]
+ ];
+
+ public function collectData()
+ {
+ $html = getSimpleHTMLDOM(self::URI . '/blog/');
+ $limit = $this->getInput('limit');
+
+ $posts = $html->find('main > section > a.group');
+ for ($i = 0; $i < min(count($posts), $limit); $i++) {
+ $post = $posts[$i];
+ $title = $post->find('h2', 0)->plaintext;
+ $date_text = $post->find('h3[datetime]', 0)->getAttribute('datetime');
+ $timestamp = (new DateTime(mb_substr($date_text, 0, 19)))->format('U');
+ $uri = self::URI . $post->getAttribute('href');
+ $this->items[] = [
+ 'uri' => $uri,
+ 'title' => $title,
+ 'timestamp' => $timestamp,
+ 'content' => $this->parsePage($uri),
+ 'uid' => $uri
+ ];
+ }
+ }
+
+ private function parsePage($uri)
+ {
+ $html = getSimpleHTMLDOMCached(
+ $uri,
+ 86400,
+ [],
+ [],
+ true,
+ true,
+ DEFAULT_TARGET_CHARSET,
+ false // Do not strip \n from <code> blocks
+ );
+ $contents = $html->find('main > article > section.prose', 0);
+ $contents = defaultLinkTo($contents, self::URI);
+ return $contents->innertext;
+ }
+}