Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from diygod:master #1289

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/utils/common-utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const { parseDate } = require('@/utils/parse-date');
const title = require('title');

// convert a string into title case
const toTitleCase = (str) =>
str
.toLowerCase()
.split(' ')
.map((word) => word.replace(word[0], word[0].toUpperCase()))
.join(' ');
const toTitleCase = (str) => title(str);

const rWhiteSpace = /\s+/;
const rAllWhiteSpace = /\s+/g;
Expand Down
4 changes: 4 additions & 0 deletions lib/v2/dut/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ module.exports = {
// 体育场馆中心:http://tycgzx.dlut.edu.cn
// 默认 -> 通知公告 http://tycgzx.dlut.edu.cn/tzgg/tzgg.htm
tycgzx: 'tzgg/tzgg',

// 公共基础学院:http://fldpj.dlut.edu.cn/index.htm
// 默认 -> 重要通知 http://fldpj.dlut.edu.cn/index/zytz.htm
fldpj: 'index/zytz',
};
30 changes: 21 additions & 9 deletions lib/v2/dut/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = async (ctx) => {

if (site === 'panjin') {
items = $('a.news').slice(0, -4);
} else if (site === 'fldpj') {
items = $('li[id^="line_u9"]').find('a');
} else {
$('.Next, .rjxw_left, .pb_sys_common').remove();
items = $('.txt, .itemlist, .wall, .list, .list01, .ny_list, .rjxw_right, .rj_yjs_con, .c_hzjl_list1, .winstyle67894, .winstyle80936, .winstyle50738, #lili').find('a');
Expand All @@ -38,18 +40,28 @@ module.exports = async (ctx) => {
.map((item) => {
item = $(item);

const dateRegex = /(\d{4}[-/年]\d{2}[-/月]\d{2})/;
const result = {
link: item.attr('href').startsWith('http') ? item.attr('href') : `${rootUrl}/${item.attr('href').replace(/^[./]+/, '')}`,
};

if (site === 'fldpj') {
result.title = item.find('em').text();
result.pubDate = parseDate(item.find('span').text());
} else {
const dateRegex = /(\d{4}[-/年]\d{2}[-/月]\d{2})/;

let dateMatch = item.parent().text().match(dateRegex);
if (!dateMatch) {
dateMatch = item.parent().parent().text().match(dateRegex);
}

let dateMatch = item.parent().text().match(dateRegex);
if (!dateMatch) {
dateMatch = item.parent().parent().text().match(dateRegex);
result.title = item.text().trim() === '' ? item.next().text() : item.text();
if (dateMatch) {
result.pubDate = parseDate(dateMatch[1].replace(/年|月/g, '-'));
}
}

return {
title: item.text() === '' ? item.next().text() : item.text(),
link: /^http/.test(item.attr('href')) ? item.attr('href') : `${rootUrl}/${item.attr('href').replace(/^[./]+/, '')}`,
pubDate: parseDate(dateMatch ? dateMatch[1].replace(/年|月/g, '-') : new Date().toString()),
};
return result;
});

items = await Promise.all(
Expand Down
15 changes: 8 additions & 7 deletions lib/v2/dut/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module.exports = {
'/news/:category?': ['nczitzk'],
'/perdep/:category?': ['nczitzk'],
'/teach/:category?': ['beautyyuyanli', 'nczitzk'],
'/gs/:category?': ['nczitzk'],
'/ssdut/:category?': ['nczitzk'],
'/dutdice/:category?': ['beautyyuyanli', 'nczitzk'],
'/eda/:category?': ['nczitzk'],
'/fldpj/:category?': ['ueiu'],
'/gs/:category?': ['nczitzk'],
'/news/:category?': ['nczitzk'],
'/panjin/:category?': ['nczitzk'],
'/xsgzb/:category?': ['nczitzk'],
'/perdep/:category?': ['nczitzk'],
'/pjteach/:category?': ['nczitzk'],
'/pjxqzwb/:category?': ['nczitzk'],
'/dutdice/:category?': ['beautyyuyanli', 'nczitzk'],
'/ssdut/:category?': ['nczitzk'],
'/teach/:category?': ['beautyyuyanli', 'nczitzk'],
'/tycgzx/:category?': ['beatyyuyanli', 'nczitzk'],
'/xsgzb/:category?': ['nczitzk'],
};
66 changes: 37 additions & 29 deletions lib/v2/dut/radar.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module.exports = {
'dlut.edu.cn': {
_name: '大连理工大学',
news: [
dutdice: [
{
title: '新闻网',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-xin-wen-wang',
title: '国际合作与交流处(港澳台办)',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-guo-ji-he-zuo-yu-jiao-liu-chu-gang-ao-tai-ban',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
perdep: [
eda: [
{
title: '人事处',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-ren-shi-chu',
title: '开发区校区',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-kai-fa-qu-xiao-qu',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
teach: [
fldpj: [
{
title: '教务处',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-jiao-wu-chu',
title: '公共基础学院',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-gong-gong-ji-chu-xue-yuan',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
Expand All @@ -33,18 +33,10 @@ module.exports = {
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
ssdut: [
{
title: '软件学院',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-ruan-jian-xue-yuan',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
eda: [
news: [
{
title: '开发区校区',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-kai-fa-qu-xiao-qu',
title: '新闻网',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-xin-wen-wang',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
Expand All @@ -57,10 +49,10 @@ module.exports = {
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
xsgzb: [
perdep: [
{
title: '盘锦校区学生事务办公室',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-pan-jin-xiao-qu-xue-sheng-shi-wu-ban-gong-shi',
title: '人事处',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-ren-shi-chu',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
Expand All @@ -81,18 +73,26 @@ module.exports = {
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
tjpj: [
ssdut: [
{
title: '体育与健康学院盘锦分院',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-ti-yu-jian-kang-xue-yuan-pan-jin-fen-yuan',
title: '软件学院',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-ruan-jian-xue-yuan',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
dutdice: [
teach: [
{
title: '国际合作与交流处(港澳台办)',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-guo-ji-he-zuo-yu-jiao-liu-chu-gang-ao-tai-ban',
title: '教务处',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-jiao-wu-chu',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
tjpj: [
{
title: '体育与健康学院盘锦分院',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-ti-yu-jian-kang-xue-yuan-pan-jin-fen-yuan',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
Expand All @@ -105,5 +105,13 @@ module.exports = {
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
xsgzb: [
{
title: '盘锦校区学生事务办公室',
docs: 'https://docs.rsshub.app/routes/university#da-lian-li-gong-da-xue-pan-jin-xiao-qu-xue-sheng-shi-wu-ban-gong-shi',
source: ['/'],
target: (params, url) => `/dut/${url.match(/:\/\/[\w\d]+\./)[1]}/${url.match(/\.cn\/(.*)\.htm/)[1]}`,
},
],
},
};
5 changes: 5 additions & 0 deletions lib/v2/dut/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ module.exports = {
xwdt: 'xwdt/xwdt',
jkzs: 'jkzs/jkzs1',
},
fldpj: {
xsdt: 'kxyj/xsdt',
zytz: 'index/zytz',
ywgk: 'index/ywgk',
},
};
63 changes: 63 additions & 0 deletions lib/v2/fxiaoke/crm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://www.fxiaoke.com/crm';
const baseTitle = '纷享销客 CRM';
const titleMap = new Map([
['news', `全部文章 - ${baseTitle}`],
['blog', `文章干货 - ${baseTitle}`],
['articles', `CRM 知识 - ${baseTitle}`],
['about-influence', `纷享动态 - ${baseTitle}`],
['customers', `签约喜报 - ${baseTitle}`],
]);

module.exports = async (ctx) => {
const t = ctx.params.type;
const title = titleMap.get(t);
const url = `${baseUrl}/${t}/`;
const resp = await got(url);
const $ = cheerio.load(resp.data);
const desc = $('.meeting').text().trim();
let items = $('.content-item')
.toArray()
.map((item) => {
item = $(item);
const c1 = item.find('.baike-content-t1');
const c3 = item.find('.baike-content-t3').find('span');
return {
title: c1.text().trim(),
// pubDate: parseDate(c3.first().text().trim()),
link: item.find('a').attr('href'),
author: c3.last().text().trim(),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const resp = await got(item.link);
const $ = cheerio.load(resp.data);
const firstViewBox = $('.body-wrapper-article').first();

firstViewBox.find('img').each((_, img) => {
img = $(img);
if (img.attr('zoomfile')) {
img.attr('src', img.attr('zoomfile'));
img.removeAttr('zoomfile');
img.removeAttr('file');
}
img.removeAttr('onmouseover');
});

item.description = firstViewBox.html();
item.pubDate = parseDate($('.month-day').first().text().trim());
return item;
})
)
);
ctx.state.data = {
title,
link: url,
description: desc,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/fxiaoke/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/crm/:type': ['akynazh'],
};
37 changes: 37 additions & 0 deletions lib/v2/fxiaoke/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
'fxiaoke.com': {
_name: '纷享销客 CRM',
'.': [
{
title: '全部文章',
docs: 'https://docs.rsshub.app/routes/blog#fen-xiang-xiao-ke-crm',
source: ['/*'],
target: '/fxiaoke/crm/news',
},
{
title: '文章干货',
docs: 'https://docs.rsshub.app/routes/blog#fen-xiang-xiao-ke-crm',
source: ['/*'],
target: '/fxiaoke/crm/blog',
},
{
title: 'CRM 知识',
docs: 'https://docs.rsshub.app/routes/blog#fen-xiang-xiao-ke-crm',
source: ['/*'],
target: '/fxiaoke/crm/articles',
},
{
title: '纷享动态',
docs: 'https://docs.rsshub.app/routes/blog#fen-xiang-xiao-ke-crm',
source: ['/*'],
target: '/fxiaoke/crm/about-influence',
},
{
title: '签约喜报',
docs: 'https://docs.rsshub.app/routes/blog#fen-xiang-xiao-ke-crm',
source: ['/*'],
target: '/fxiaoke/crm/customers',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/fxiaoke/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/crm/:type', require('./crm'));
};
44 changes: 44 additions & 0 deletions lib/v2/sspu/jwc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const { listId } = ctx.params;
const baseUrl = 'https://jwc.sspu.edu.cn';

const { data: response, url: link } = await got(`${baseUrl}/${listId}/list.htm`);
const $ = cheerio.load(response);

const list = $('.news_list .news')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 15)
.toArray()
.map((item) => {
item = $(item);
const title = item.find('.news_title a');
return {
title: title.attr('title'),
link: `${baseUrl}${title.attr('href')}`,
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

item.description = $('.wp_articlecontent').html();
item.pubDate = timezone(parseDate($('.arti_update').text(), 'YYYY-MM-DD HH:mm:ss'), +8);

return item;
})
)
);

ctx.state.data = {
title: $('head title').text(),
link,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/sspu/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/jwc/:listId': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/sspu/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'sspu.edu.cn': {
_name: '上海第二工业大学',
jwc: [
{
title: '教务处',
docs: 'https://docs.rsshub.app/university#shang-hai-di-er-gong-ye-da-xue',
source: ['/jwc/:listId/list.htm'],
target: '/sspu/jwc/:listId',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/sspu/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/jwc/:listId', require('./jwc'));
};
Loading
Loading