Skip to content

Commit

Permalink
Merge pull request #293 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Aug 30, 2023
2 parents ae82bc5 + 121763b commit 603327f
Show file tree
Hide file tree
Showing 29 changed files with 401 additions and 219 deletions.
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const calculateValue = () => {
debugInfo: envs.DEBUG_INFO || 'true',
loggerLevel: envs.LOGGER_LEVEL || 'info',
noLogfiles: envs.NO_LOGFILES,
showLoggerTimestamp: envs.SHOW_LOGGER_TIMESTAMP,
sentry: {
dsn: envs.SENTRY,
routeTimeout: parseInt(envs.SENTRY_ROUTE_TIMEOUT) || 30000,
Expand Down
10 changes: 5 additions & 5 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ router.get('/huya/live/:id', lazyloadRouteHandler('./routes/huya/live'));
router.get('/showroom/room/:id', lazyloadRouteHandler('./routes/showroom/room'));

// v2ex
router.get('/v2ex/topics/:type', lazyloadRouteHandler('./routes/v2ex/topics'));
router.get('/v2ex/post/:postid', lazyloadRouteHandler('./routes/v2ex/post'));
router.get('/v2ex/tab/:tabid', lazyloadRouteHandler('./routes/v2ex/tab'));
// router.get('/v2ex/topics/:type', lazyloadRouteHandler('./routes/v2ex/topics'));
// router.get('/v2ex/post/:postid', lazyloadRouteHandler('./routes/v2ex/post'));
// router.get('/v2ex/tab/:tabid', lazyloadRouteHandler('./routes/v2ex/tab'));

// f-droid
router.get('/fdroid/apprelease/:app', lazyloadRouteHandler('./routes/fdroid/apprelease'));
Expand Down Expand Up @@ -908,7 +908,7 @@ router.get('/paidai/bbs', lazyloadRouteHandler('./routes/paidai/bbs'));
router.get('/paidai/news', lazyloadRouteHandler('./routes/paidai/news'));

// 中国银行
router.get('/boc/whpj/:format?', lazyloadRouteHandler('./routes/boc/whpj'));
// router.get('/boc/whpj/:format?', lazyloadRouteHandler('./routes/boc/whpj'));

// 漫画db
router.get('/manhuadb/comics/:id', lazyloadRouteHandler('./routes/manhuadb/comics'));
Expand Down Expand Up @@ -2039,7 +2039,7 @@ router.get('/anki/changes', lazyloadRouteHandler('./routes/anki/changes'));
router.get('/abc/:id?', lazyloadRouteHandler('./routes/abc'));

// 台湾中央通讯社
router.get('/cna/:id?', lazyloadRouteHandler('./routes/cna/index'));
// router.get('/cna/:id?', lazyloadRouteHandler('./routes/cna/index'));

// 华为心声社区
router.get('/huawei/xinsheng/:caty?/:order?/:keyword?', lazyloadRouteHandler('./routes/huawei/xinsheng/index'));
Expand Down
39 changes: 0 additions & 39 deletions lib/routes/v2ex/post.js

This file was deleted.

16 changes: 14 additions & 2 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ if (!config.noLogfiles) {
}
const logger = winston.createLogger({
level: config.loggerLevel,
format: winston.format.json(),
format: winston.format.combine(
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
winston.format.printf((info) =>
JSON.stringify({
timestamp: info.timestamp,
level: info.level,
message: info.message,
})
)
),
transports,
});

Expand All @@ -25,7 +34,10 @@ const logger = winston.createLogger({
if (!config.isPackage) {
logger.add(
new winston.transports.Console({
format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
format: winston.format.printf((info) => {
const infoLevel = winston.format.colorize().colorize(info.level, config.showLoggerTimestamp ? `[${info.timestamp}] ${info.level}` : info.level);
return `${infoLevel}: ${info.message}`;
}),
silent: process.env.NODE_ENV === 'test',
})
);
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/boc/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/whpj/:format?': ['LogicJake', 'HenryQW'],
};
13 changes: 13 additions & 0 deletions lib/v2/boc/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'boc.cn': {
_name: '中国银行',
'.': [
{
title: '外汇牌价',
docs: 'https://docs.rsshub.app/routes/others#zhong-guo-yin-hang',
source: ['/sourcedb/whpj', '/'],
target: '/boc/whpj',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/boc/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/whpj/:format?', require('./whpj'));
};
16 changes: 8 additions & 8 deletions lib/routes/boc/whpj.js → lib/v2/boc/whpj.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const link = 'http://www.boc.cn/sourcedb/whpj/';
const response = await got.get(link);
const link = 'https://www.boc.cn/sourcedb/whpj/';
const response = await got(link);
const $ = cheerio.load(response.data);

const format = ctx.params.format;
Expand Down Expand Up @@ -40,11 +40,12 @@ module.exports = async (ctx) => {

const out = $('div.publish table tbody tr')
.slice(2)
.toArray()
.map(function () {
const zh_name = $(this).find('td:nth-child(1)').text();
const en_name = en_names[zh_name] || '';
const name = `${zh_name} ${en_name} `;
const date = `${$(this).find('td:nth-child(7)').text()} ${$(this).find('td:nth-child(8)').text()}`;
const name = `${zh_name} ${en_name}`;
const date = $(this).find('td:nth-child(7)').text();

const xhmr = `现汇买入价:${$(this).find('td:nth-child(2)').text()}`;

Expand Down Expand Up @@ -77,19 +78,18 @@ module.exports = async (ctx) => {
case 'xcmc':
return `${name} ${xcmc}`;
default:
return name + content;
return `${name} ${content}`;
}
};

const info = {
title: formatTitle(),
description: content.replace(/\s/g, '<br>'),
pubDate: new Date(date).toUTCString(),
guid: name + date,
guid: `${name} ${content}`,
};
return info;
})
.get();
});

ctx.state.data = {
title: '中国银行外汇牌价',
Expand Down
22 changes: 12 additions & 10 deletions lib/routes/cna/index.js → lib/v2/cna/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
ctx.params.id = ctx.params.id || 'aall';
const id = ctx.params.id || 'aall';

let rootUrl;

if (/^\d+$/.test(ctx.params.id)) {
rootUrl = `https://www.cna.com.tw/topic/newstopic/${ctx.params.id}.aspx`;
if (/^\d+$/.test(id)) {
rootUrl = `https://www.cna.com.tw/topic/newstopic/${id}.aspx`;
} else {
rootUrl = `https://www.cna.com.tw/list/${ctx.params.id}.aspx`;
rootUrl = `https://www.cna.com.tw/list/${id}.aspx`;
}
const response = await got({
method: 'get',
url: rootUrl,
});

const $ = cheerio.load(response.data);
const list = $('#jsMainList li a div h2')
.slice(0, 10)
.map((_, item) => {
const list = $('.mainList li a div h2')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
.toArray()
.map((item) => {
item = $(item);
return {
title: item.text(),
link: item.parents('a').attr('href'),
pubDate: new Date(item.next().text() + ' GMT+8').toUTCString(),
pubDate: timezone(parseDate(item.next().text()), +8),
};
})
.get();
});

const items = await Promise.all(
list.map((item) =>
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/cna/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:id?': ['nczitzk'],
};
13 changes: 13 additions & 0 deletions lib/v2/cna/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'cna.com.tw': {
_name: '中央通訊社',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/routes/traditional-media#zhong-yang-tong-xun-she',
source: ['/list/:id', '/topic/newstopic/:id'],
target: (params) => `/cna/${params.id.replace('.aspx', '')}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cna/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:id?', require('./'));
};
2 changes: 1 addition & 1 deletion lib/v2/discourse/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = async (ctx) => {
const response = await got(`${link}/notifications.json`, { headers: { 'User-Api-Key': key } }).json();
const items = response.notifications.map((e) => ({
title: e.fancy_title ?? e.data.badge_name,
link: `${link}/${e.data.hasOwnProperty('badge_id') ? `badges/${e.data.badge_id}/${e.data.badge_slug}?username=${e.data.username}` : `${e.topic_id}/${e.post_number}`}`,
link: `${link}/${e.data.hasOwnProperty('badge_id') ? `badges/${e.data.badge_id}/${e.data.badge_slug}?username=${e.data.username}` : `t/topic/${e.topic_id}/${e.post_number}`}`,
pubDate: new Date(e.created_at),
author: e.data.display_username ?? e.data.username,
category: `notification_type:${e.notification_type}`,
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/icbc/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/whpj/:format?': ['leoleoasd'],
};
13 changes: 13 additions & 0 deletions lib/v2/icbc/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'icbc.com.cn': {
_name: '中国工商银行',
'.': [
{
title: '外汇牌价',
docs: 'https://docs.rsshub.app/other#zhong-guo-gong-shang-yin-hang',
source: ['/column/1438058341489590354.html'],
target: '/icbc/whpj',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/icbc/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/whpj/:format?', require('./whpj'));
};
57 changes: 57 additions & 0 deletions lib/v2/icbc/whpj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const got = require('@/utils/got');

module.exports = async (ctx) => {
// yes, insecure
// their openssl version isn't safe anyway (https://stackoverflow.com/questions/75763525/curl-35-error0a000152ssl-routinesunsafe-legacy-renegotiation-disabled)
const { data } = await got('http://papi.icbc.com.cn/exchanges/ns/getLatest');
const format = ctx.params.format;

ctx.state.data = {
title: '中国工商银行外汇牌价',
link: 'https://www.icbc.com.cn/column/1438058341489590354.html',
item: data.data.map((item) => {
const name = `${item.currencyCHName} ${item.currencyENName}`;

const xhmr = `现汇买入价:${item.foreignBuy}`;

const xcmr = `现钞买入价:${item.cashBuy}`;

const xhmc = `现汇卖出价:${item.foreignSell}`;

const xcmc = `现钞卖出价:${item.cashSell}`;

const zs = `参考价:${item.reference}`;

const content = `${xhmr} ${xcmr} ${xhmc} ${xcmc} ${zs}`;

const formatTitle = () => {
switch (format) {
case 'short':
return name;
case 'xh':
return `${name} ${xhmr} ${xhmc}`;
case 'xc':
return `${name} ${xcmr} ${xcmc}`;
case 'zs':
return `${name} ${zs}`;
case 'xhmr':
return `${name} ${xhmr}`;
case 'xhmc':
return `${name} ${xhmc}`;
case 'xcmr':
return `${name} ${xcmr}`;
case 'xcmc':
return `${name} ${xcmc}`;
default:
return `${name} ${content}`;
}
};
return {
title: formatTitle(),
pubDate: new Date(`${item.publishDate} ${item.publishTime}`),
description: content.replace(/\s/g, '<br>'),
guid: `${name} ${item.publishDate} ${item.publishTime}`,
};
}),
};
};
5 changes: 5 additions & 0 deletions lib/v2/v2ex/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'/post/:postid': ['kt286'],
'/tab/:tabid': ['liyefox'],
'/topics/:type': ['WhiteWorld'],
};
35 changes: 35 additions & 0 deletions lib/v2/v2ex/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { postid } = ctx.params;
const pageUrl = `https://www.v2ex.com/t/${postid}`;

const { data: topicResponse } = await got('https://www.v2ex.com/api/topics/show.json', {
searchParams: {
id: postid,
},
});

const { data: replies } = await got('https://www.v2ex.com/api/replies/show.json', {
searchParams: {
topic_id: postid,
},
});

const topic = topicResponse[0];

ctx.state.data = {
title: `V2EX-${topic.title}`,
link: pageUrl,
description: topic.content,
item: replies.map((item, index) => ({
title: `#${index + 1} ${item.content}`,
description: item.content_rendered,
link: `${pageUrl}#r_${item.id}`,
author: item.member.username,
pubDate: parseDate(item.created, 'X'),
})),
allowEmpty: true,
};
};
Loading

0 comments on commit 603327f

Please sign in to comment.