moztw / www.moztw.org

Repository of moztw.org
https://moztw.org/
Mozilla Public License 2.0
55 stars 59 forks source link

修復首頁 RSS #679

Closed irvin closed 2 years ago

irvin commented 3 years ago

首頁中間的 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 收了。所以今年初開始就不正常了。

可能解法:

截圖 2021-09-04 下午5 04 26
irvin commented 3 years ago

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

截圖 2021-09-04 下午7 43 18
irvin commented 2 years ago
截圖 2021-10-06 下午9 19 42

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

irvin commented 2 years ago

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

mingtsay commented 2 years ago

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

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

RJHsiao commented 2 years ago

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

RJHsiao commented 2 years ago

https://www.npmjs.com/package/rss-to-json

chyuaner commented 2 years ago

簡易的抓取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;
pan93412 commented 2 years ago

簡易的抓取 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))
);
mingtsay commented 2 years ago

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