moztw / www.moztw.org

Repository of moztw.org

Home Page:https://moztw.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

修復首頁 RSS

irvin opened this issue · comments

首頁中間的 RSS 聯播,會用 js 叫一個 json 回來組出聯播區塊,但現有的 RSS 轉 JSON 服務是透過 integromat 組裝,直接讓所有 client 都去叫 Integromat 會超過免費方案的 budget。

需要有人幫忙弄一個 node 或者 php 的 api cache service,每次有人去叫這個 api 時,就直接從 cache 中吐回 json;然後每天 invalid 一次再去跟後面 integromat 要更新的 RSS JSON。


每 24 小時去這個 endpoint 拿回 JSON 物件
https://hook.us1.make.com/lvow76y9di4s3swd8hj27preuwjm053u


或者在主機上把 https://planet.moztw.org/atom.xml 轉成 JSON API


下面舊資訊不用看

中間這一塊過去仰賴 cors-anywhere 這個服務把 json proxy 過,但是他們提供的 demo server 收了。所以今年初開始就不正常了。

可能解法:

  • 自己架
  • 幫 planetplanet 加上出 JSON 功能與 acept-control allow-origin header
  • 另尋他法

截圖 2021-09-04 下午5 04 26

結果先用 integromat 拼湊了一個 api 起來,只是免費帳號流量應該不夠,先觀察個兩天看看

截圖 2021-09-04 下午7 43 18

截圖 2021-10-06 下午9 19 42

一個月的流量大概 5MB / 9000 operation 左右,如果是收費帳號大概需要 9 USD

如果有人可以幫忙在主機上寫一個 cache,就應該可以不用錢

如果有人可以幫忙在主機上寫一個 cache,就應該可以不用錢

我沒有存取權限,如果要協助的話我頂多可以提供在我主機上加 header

原始資料路徑:https://planet.moztw.org/atom.xml
這個我寫個 parser 轉 json 出來就好

簡易的抓取xml並轉json的PHP腳本

// 用法: $ php demo.php > demo.json

$url = 'https://planet.moztw.org/atom.xml';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$xml=simplexml_load_string($result);
$jsonS = json_encode($xml);

//header('Content-Type: application/json; charset=utf-8');
echo $jsonS;

簡易的抓取 xml 並轉 json 的 JS 腳本:

require('rss-to-json').parse('https://blog.ethereum.org/feed.xml').then(rss =>
    require('fs').promises.writeFile("./data.json", JSON.stringify(rss))
);

You may integrate the RSS on the index page this repo:
https://github.com/moztw/planet-rss-json

It provides the JSON per day 02:34 UTC