Skip to content

Commit

Permalink
Merge pull request #1319 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 Jan 9, 2024
2 parents e18d913 + 377dd9f commit 3d22aef
Show file tree
Hide file tree
Showing 28 changed files with 457 additions and 124 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ router.get('/4gamers/tag/:tag', lazyloadRouteHandler('./routes/4gamers/tag'));
router.get('/4gamers/topic/:topic', lazyloadRouteHandler('./routes/4gamers/topic'));

// 大麦网
router.get('/damai/activity/:city/:category/:subcategory/:keyword?', lazyloadRouteHandler('./routes/damai/activity'));
// router.get('/damai/activity/:city/:category/:subcategory/:keyword?', lazyloadRouteHandler('./routes/damai/activity'));

// 桂林电子科技大学新闻资讯
router.get('/guet/xwzx/:type?', lazyloadRouteHandler('./routes/guet/news'));
Expand Down
28 changes: 0 additions & 28 deletions lib/routes/damai/activity.js

This file was deleted.

57 changes: 57 additions & 0 deletions lib/v2/acpaa/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { id = '1', name = '重要通知' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;

const rootUrl = 'http://www.acpaa.cn';
const currentUrl = new URL(`article/taglist.jhtml?tagIds=${id}&tagname=${name}`, rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

let items = $('div.text01 ul li a[title]')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

return {
title: item.prop('title'),
link: new URL(item.prop('href'), rootUrl).href,
pubDate: timezone(parseDate(item.find('span[title]').prop('title')), +8),
};
});

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

const content = cheerio.load(detailResponse);

item.title = content('div.xhjj_head01').text();
item.description = content('div.text01').html();

return item;
})
)
);

const author = $('title').text().replace(/-/g, '');
const subtitle = $('span.myTitle').text().trim();

ctx.state.data = {
item: items,
title: `${author} - ${subtitle}`,
link: currentUrl,
description: $('meta[property="og:description"]').prop('content'),
language: 'zh',
subtitle,
author,
};
};
3 changes: 3 additions & 0 deletions lib/v2/acpaa/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:id?/:name?': ['nczitzk'],
};
19 changes: 19 additions & 0 deletions lib/v2/acpaa/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'acpaa.cn': {
_name: '中华全国专利代理师协会',
'.': [
{
title: '文章',
docs: 'https://docs.rsshub.app/routes/other#zhong-hua-quan-guo-zhuan-li-dai-li-shi-xie-hui',
source: ['/article/taglist.jhtml'],
target: (url) => {
url = new URL(url);
const id = url.searchParams.get('id');
const name = url.searchParams.get('name');

return `/acpaa${id ? `/${id}${name ? `/${name}` : ''}` : ''}`;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/acpaa/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:id?/:name?', require('./'));
};
44 changes: 44 additions & 0 deletions lib/v2/damai/activity.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 { art } = require('@/utils/render');
const { join } = require('path');

module.exports = async (ctx) => {
const city = ctx.params.city === '全部' ? '' : ctx.params.city;
const category = ctx.params.category === '全部' ? '' : ctx.params.category;
const subcategory = ctx.params.subcategory === '全部' ? '' : ctx.params.subcategory;
const keyword = ctx.params.keyword ? ctx.params.keyword : '';

const url = 'https://search.damai.cn/searchajax.html';

const response = await got(url, {
searchParams: {
keyword,
cty: city,
ctl: category,
sctl: subcategory,
tsg: 0,
st: '',
et: '',
order: 3,
pageSize: 30,
currPage: 1,
tn: '',
},
});
const data = response.data;
const list = data.pageData.resultData || [];

ctx.state.data = {
title: `大麦网票务 - ${city || '全国'} - ${category || '全部分类'}${subcategory ? ' - ' + subcategory : ''}${keyword ? ' - ' + keyword : ''}`,
link: 'https://search.damai.cn/search.htm',
item: list.map((item) => ({
title: item.nameNoHtml,
author: item.actors ? cheerio.load(item.actors, null, false).text() : '大麦网',
description: art(join(__dirname, 'templates/activity.art'), {
item,
}),
link: `https://detail.damai.cn/item.htm?id=${item.projectid}`,
})),
};
};
3 changes: 3 additions & 0 deletions lib/v2/damai/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/activity/:city/:category/:subcategory/:keyword?': ['hoilc'],
};
13 changes: 13 additions & 0 deletions lib/v2/damai/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'damai.cn': {
_name: '大麦网',
search: [
{
title: '票务更新',
docs: 'https://docs.rsshub.app/routes/shopping#da-mai-wang',
source: ['/search.html'],
target: (_params, url) => `/damai/activity/全部/全部/全部/${new URL(url).searchParams.get('keyword') || ''}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/damai/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/activity/:city/:category/:subcategory/:keyword?', require('./activity'));
};
5 changes: 5 additions & 0 deletions lib/v2/damai/templates/activity.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<img src="{{ item.verticalPic }}">
<p>{{@ item.description }}</p>
<p>地点:{{ item.venuecity }} | {{ item.venue }}</p>
<p>时间:{{ item.showtime }}</p>
<p>票价:{{ item.price_str }}</p>
4 changes: 2 additions & 2 deletions lib/v2/shiep/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const config = {
jjc: { title: '基建处', id: '327' },
jjxy: { title: '继续教育学院(国际教育学院)', id: '2582' },
jsjxfzzx: { title: '教师教学发展中心', id: '3909' },
jsjxy: { title: '计算机科学与技术学院', id: 'xygg', listSelector: 'div.post-entry-2', pubDateSelector: 'span:nth-child(2)' },
jsjxy: { title: '计算机科学与技术学院', id: 'xygg', listSelector: 'div.xylist', pubDateSelector: 'span:nth-child(2)' },
jszyzx: { title: '技术转移中心', id: '4247' },
jwc: { title: '教务处', id: '227' },
jwc: { title: '教务处', id: '227', listSelector: 'div.text-list li', pubDateSelector: 'span.time' },
jxfz: { title: '电力装备设计与制造虚拟仿真中心', id: '3330' },
kczx: { title: '能源电力科创中心', id: '3946' },
kyc: { title: '科研处/融合办', id: '834' },
Expand Down
29 changes: 16 additions & 13 deletions lib/v2/shiep/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ module.exports = async (ctx) => {
const type = ctx.params.type;

if (!Object.keys(config).includes(type)) {
throw Error('Invalid type');
throw Error(`Invalid type: ${type}`);
}

const { listSelector = '.list_item', pubDateSelector = '.Article_PublishDate', descriptionSelector = '.wp_articlecontent', title } = config[type];

if (!title) {
throw Error(`Invalid type: ${type}`);
}

const host = `https://${type}.shiep.edu.cn`;
Expand All @@ -20,23 +26,21 @@ module.exports = async (ctx) => {
const response = await got(link);
const $ = cheerio.load(response.data);

const listSelector = config[type].listSelector || '.list_item';
const pubDateSelector = config[type].pubDateSelector || '.Article_PublishDate';
const descriptionSelector = config[type].descriptionSelector || '.wp_articlecontent';

const list = $(listSelector)
.toArray()
.filter((item) => {
const date = dayjs($(item).find(pubDateSelector).text().trim());
return date.isValid();
})
.map((item) => {
item = $(item);
const pubDateText = item.find(pubDateSelector).text().trim();
const match = pubDateText.match(/\b(\d{4}-\d{2}-\d{2})\b/);
return {
title: item.find('a').attr('title') || item.find('a').text(),
title: item.find('a').attr('title') || item.find('h3').text() || item.find('a').text(),
link: new URL(item.find('a').attr('href'), host).href,
pubDate: parseDate(item.find(pubDateSelector).text().trim(), 'YYYY-MM-DD'),
pubDate: match ? parseDate(match[0], 'YYYY-MM-DD') : null,
};
})
.filter((item) => {
const date = dayjs(item.pubDate);
return date.isValid();
});

const items = await Promise.all(
Expand All @@ -62,9 +66,8 @@ module.exports = async (ctx) => {
);

ctx.state.data = {
title: '上海电力大学-' + config[type].title,
title: `上海电力大学-${title}`,
link,
description: '上海电力大学-' + config[type].title,
item: items,
};
};
87 changes: 65 additions & 22 deletions lib/v2/tradingview/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,98 @@ const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const language = ctx.params.language ?? 'en';
const { category = 'en' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 22;

const rootUrl = 'https://www.tradingview.com';
const currentUrl = `${rootUrl}/blog/${language}`;
const currentUrl = new URL(`blog/${category.endsWith('/') ? category : `${category}/`}`, rootUrl).href;

const response = await got({
method: 'get',
url: currentUrl,
});
const { data: response } = await got(currentUrl);

const $ = cheerio.load(response.data);
const $ = cheerio.load(response);

const list = $('.articles-grid-item a[rel="bookmark"]')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
const items = $('article[id]')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const title = item.find('div.title').text();

return {
title: item.find('.title').text(),
link: item.attr('href'),
pubDate: parseDate(item.find('.date').text(), 'MMMM D, YYYY'),
title,
link: item.find('a.articles-grid-link').prop('href'),
description: art(path.join(__dirname, 'templates/description.art'), {
image: {
src: item
.find('div.articles-grid-img img')
.prop('src')
.replace(/-\d+x\d+\./, '.'),
alt: title,
},
}),
category: item
.find('a.section')
.toArray()
.map((c) => $(c).text()),
guid: `tradingview-blog-${category}-${item.prop('id')}`,
pubDate: parseDate(item.find('div.date').text(), 'MMM D, YYYY'),
};
});

const items = [];
for await (const item of asyncPool(3, list, (item) =>
for await (const item of asyncPool(3, items, (item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const { data: detailResponse } = await got(item.link);

const content = cheerio.load(detailResponse);

const content = cheerio.load(detailResponse.data);
content('div.entry-content')
.find('img')
.each((_, e) => {
content(e).replaceWith(
art(path.join(__dirname, 'templates/description.art'), {
image: {
src: content(e)
.prop('src')
.replace(/-\d+x\d+\./, '.'),
width: content(e).prop('width'),
height: content(e).prop('height'),
},
})
);
});

item.title = content('meta[property="og:title"]').prop('content');
item.description = art(path.join(__dirname, 'templates/description.art'), {
image: content('.single-img img').attr('src'),
description: content('.entry-content').html(),
image: {
src: content('meta[property="og:image"]').prop('content'),
alt: item.title,
},
description: content('div.entry-content').html(),
});
item.author = content('meta[property="og:site_name"]').prop('content');
item.category = content('div.sections a.section')
.toArray()
.map((c) => content(c).text());
item.pubDate = parseDate(content('div.single-date').text(), 'MMM D, YYYY');

return item;
})
)) {
items.shift();
items.push(item);
}

const icon = new URL($('link[rel="icon"]').prop('href'), rootUrl).href;

ctx.state.data = {
item: items,
title: $('title').text(),
link: currentUrl,
item: items,
description: $('div.site-subtitle').text(),
language: $('html').prop('lang'),
icon,
logo: icon,
subtitle: $('h1.site-title').text(),
};
};
2 changes: 1 addition & 1 deletion lib/v2/tradingview/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
'/blog/:language?': ['nczitzk'],
'/blog/:language?/category/:category?': ['nczitzk'],
};
Loading

0 comments on commit 3d22aef

Please sign in to comment.