mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-21 12:49:53 +08:00
fix(route): wise (#11044)
This commit is contained in:
+10
-10
@@ -205,16 +205,6 @@ Official Website: <https://news.yahoo.co.jp/pages/article/20200207>
|
||||
|
||||
<RouteEn author="sbilly" example="/sans/summit_archive" path="/sans/summit_archive" />
|
||||
|
||||
## TransferWise
|
||||
|
||||
### FX Pair Yesterday
|
||||
|
||||
<RouteEn author="HenryQW" example="/transferwise/pair/GBP/USD" path="/transferwise/pair/:source/:target" :paramsDesc="['Base currency abbreviation','Quote currency abbreviation']">
|
||||
|
||||
Refer to [the list of supported currencies](https://transferwise.com/tools/exchange-rate-alerts/).
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Trending Search Keyword Aggregator
|
||||
|
||||
### Aggregated Keyword Tracker
|
||||
@@ -257,6 +247,16 @@ Type
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Wise
|
||||
|
||||
### FX Pair Yesterday
|
||||
|
||||
<RouteEn author="HenryQW" example="/wise/pair/GBP/USD" path="/wise/pair/:source/:target" :paramsDesc="['Base currency abbreviation','Quote currency abbreviation']" radar="1">
|
||||
|
||||
Refer to [the list of supported currencies](https://wise.com/tools/exchange-rate-alerts/).
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## 裏垢女子まとめ
|
||||
|
||||
### Homepage
|
||||
|
||||
+10
-10
@@ -269,16 +269,6 @@ pageClass: routes
|
||||
|
||||
<Route author="sbilly" example="/sans/summit_archive" path="/sans/summit_archive" />
|
||||
|
||||
## TransferWise
|
||||
|
||||
### 昨日汇率变动
|
||||
|
||||
<Route author="HenryQW" example="/transferwise/pair/GBP/USD" path="/transferwise/pair/:source/:target" :paramsDesc="['本币缩写','外币缩写']">
|
||||
|
||||
参见支持的[货币列表](https://transferwise.com/tools/exchange-rate-alerts/)。
|
||||
|
||||
</Route>
|
||||
|
||||
## TSSstatus(iOS 降级通道)
|
||||
|
||||
### Status
|
||||
@@ -328,6 +318,16 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
|
||||
</Route>
|
||||
|
||||
## Wise
|
||||
|
||||
### 昨日汇率变动
|
||||
|
||||
<Route author="HenryQW" example="/wise/pair/GBP/USD" path="/wise/pair/:source/:target" :paramsDesc="['本币缩写','外币缩写']" radar="1">
|
||||
|
||||
参见支持的 [货币列表](https://wise.com/tools/exchange-rate-alerts/)。
|
||||
|
||||
</Route>
|
||||
|
||||
## 艾瑞
|
||||
|
||||
### 产业研究报告
|
||||
|
||||
+1
-1
@@ -2258,7 +2258,7 @@ router.get('/remote-work/:caty?', lazyloadRouteHandler('./routes/remote-work/ind
|
||||
router.get('/chinatimes/:caty', lazyloadRouteHandler('./routes/chinatimes/index'));
|
||||
|
||||
// TransferWise
|
||||
router.get('/transferwise/pair/:source/:target', lazyloadRouteHandler('./routes/transferwise/pair'));
|
||||
// router.get('/transferwise/pair/:source/:target', lazyloadRouteHandler('./routes/transferwise/pair'));
|
||||
|
||||
// chocolatey
|
||||
router.get('/chocolatey/software/:name?', lazyloadRouteHandler('./routes/chocolatey/software'));
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
const got = require('@/utils/got');
|
||||
const dayjs = require('dayjs');
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
dayjs.extend(customParseFormat);
|
||||
let yesterday = dayjs().subtract(1, 'day');
|
||||
const dayBefore = yesterday.subtract(1, 'day').format('YYYY-MM-DD');
|
||||
|
||||
yesterday = yesterday.format('YYYY-MM-DD');
|
||||
|
||||
const guid = `${ctx.params.source}-${ctx.params.target}-${yesterday}`;
|
||||
const cache = await ctx.cache.get(guid);
|
||||
|
||||
const link = 'https://transferwise.com/tools/exchange-rate-alerts/';
|
||||
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
} else {
|
||||
const source = ctx.params.source.toUpperCase();
|
||||
const target = ctx.params.target.toUpperCase();
|
||||
const api = `https://api.transferwise.com/v1/rates?source=${source}&target=${target}&from=${dayBefore}&to=${dayjs().format('YYYY-MM-DDTHH:mm:ssZ')}&group=day`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: api,
|
||||
headers: {
|
||||
Referer: 'https://transferwise.com/tools/exchange-rate-alerts/',
|
||||
authorization: 'Basic OGNhN2FlMjUtOTNjNS00MmFlLThhYjQtMzlkZTFlOTQzZDEwOjliN2UzNmZkLWRjYjgtNDEwZS1hYzc3LTQ5NGRmYmEyZGJjZA==',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
const yRate = data[1];
|
||||
const byRate = data[2];
|
||||
const trend = yRate.rate > byRate.rate;
|
||||
const diff = (yRate.rate - byRate.rate) / yRate.rate;
|
||||
|
||||
const percent = (Math.abs(diff) * 100).toFixed(4);
|
||||
|
||||
const title = `${source}/${target} ${trend ? '📈' : '📉'} @${yRate.rate} ${diff > 0 ? '' : '-'}${percent}%`;
|
||||
|
||||
const description = `<h3>${source} to ${target}</h3><table><tbody><tr><th align="left" style="border: 1px solid black;">Date</th><th align="left" style="border: 1px solid black;">Rate</th></tr><tr><td style="border: 1px solid black;">${yesterday}</td><td style="border: 1px solid black;">${yRate.rate}</td></tr><tr><td style="border: 1px solid black;">${dayBefore}</td><td style="border: 1px solid black;">${byRate.rate}</td></tr></tbody></table>`;
|
||||
|
||||
const single = {
|
||||
title,
|
||||
description,
|
||||
pubDate: new Date().toUTCString(),
|
||||
guid,
|
||||
link,
|
||||
};
|
||||
|
||||
ctx.cache.set(guid, JSON.stringify(ctx.state.data));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${source} to ${target} by TransferWise`,
|
||||
link,
|
||||
description: `Exchange Rate from TransferWise`,
|
||||
item: [single],
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/pair/:source/:target': ['HenryQW'],
|
||||
};
|
||||
@@ -0,0 +1,65 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const dayjs = require('dayjs');
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat');
|
||||
dayjs.extend(customParseFormat);
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const renderDesc = (content) => art(path.join(__dirname, 'templates/description.art'), content);
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let yesterday = dayjs().subtract(1, 'day');
|
||||
const dayBefore = yesterday.subtract(1, 'day').format('YYYY-MM-DD');
|
||||
yesterday = yesterday.format('YYYY-MM-DD');
|
||||
|
||||
const source = ctx.params.source.toUpperCase();
|
||||
const target = ctx.params.target.toUpperCase();
|
||||
|
||||
const link = 'https://wise.com/tools/exchange-rate-alerts/';
|
||||
const guid = `wise:rates:${ctx.params.source}-${ctx.params.target}-${yesterday}`;
|
||||
const single = await ctx.cache.tryGet(guid, async () => {
|
||||
const { data } = await got('https://wise.com/rates/history', {
|
||||
searchParams: {
|
||||
source,
|
||||
target,
|
||||
length: 1,
|
||||
unit: 'year',
|
||||
resolution: 'daily',
|
||||
},
|
||||
headers: {
|
||||
referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
const yData = data[data.length - 1];
|
||||
const byDate = data[data.length - 2];
|
||||
const yRate = yData.value;
|
||||
const byRate = byDate.value;
|
||||
const trend = yRate > byRate;
|
||||
const diff = (yRate - byRate) / yRate;
|
||||
|
||||
const percent = (Math.abs(diff) * 100).toFixed(4);
|
||||
|
||||
return {
|
||||
title: `${source}/${target} ${trend ? '📈' : '📉'} @${yRate} ${diff > 0 ? '' : '-'}${percent}%`,
|
||||
description: renderDesc({
|
||||
source,
|
||||
target,
|
||||
yesterday,
|
||||
yRate,
|
||||
dayBefore,
|
||||
byRate,
|
||||
}),
|
||||
pubDate: parseDate(yData.time, 'x'),
|
||||
guid,
|
||||
link,
|
||||
};
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${source} to ${target} by Wise`,
|
||||
link,
|
||||
description: `Exchange Rate from Wise`,
|
||||
item: [single],
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
'wise.com': {
|
||||
_name: 'Wise',
|
||||
'.': [
|
||||
{
|
||||
title: '昨日汇率变动',
|
||||
docs: 'https://docs-rsshub.pages.dev/other.html#wise',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/pair/:source/:target', require('./pair'));
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
<h3>{{ source }} to {{ target }}</h3>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th align="left" style="border: 1px solid black;">Date</th>
|
||||
<th align="left" style="border: 1px solid black;">Rate</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 1px solid black;">{{ yesterday }}</td>
|
||||
<td style="border: 1px solid black;">{{ yRate }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 1px solid black;">{{ dayBefore }}</td>
|
||||
<td style="border: 1px solid black;">{{ byRate }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user