Skip to content

Commit

Permalink
Merge branch 'DIYgod:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
falling authored Jan 10, 2024
2 parents 60e4a1a + f8a432e commit cb4e0ab
Show file tree
Hide file tree
Showing 47 changed files with 770 additions and 136 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>
64 changes: 64 additions & 0 deletions lib/v2/ekantipur/issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Require necessary modules
const got = require('@/utils/got'); // a customised got
const cheerio = require('cheerio'); // an HTML parser with a jQuery-like API

module.exports = async (ctx) => {
// Your logic here
// Defining base URL
const baseUrl = 'https://ekantipur.com';

// Retrive the channel parameter
const { channel = 'news' } = ctx.params;

// Fetches content of the requested channel
const { data: response } = await got(`${baseUrl}/${channel}`);
const $ = cheerio.load(response);

// Retrive articles
const list = $('article.normal')
// We use the `toArray()` method to retrieve all the DOM elements selected as an array.
.toArray()
// We use the `map()` method to traverse the array and parse the data we need from each element.
.map((item) => {
item = $(item);
const a = item.find('a').first();
return {
title: a.text(),
// We need an absolute URL for `link`, but `a.attr('href')` returns a relative URL.
link: `${baseUrl}${a.attr('href')}`,
author: item.find('div.author').text(),
category: channel,
};
});

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);

// Remove sponsor elements
$('a.static-sponsor').remove();
$('div.ekans-wrapper').remove();

// Fetch title from the article page
item.title = $('h1.eng-text-heading').text();
// Fetch article content from the article page
item.description = $('div.current-news-block').first().html();

// Every property of a list item defined above is reused here
// and we add a new property 'description'
return item;
})
)
);

ctx.state.data = {
// channel title
title: `Ekantipur - ${channel}`,
// channel link
link: `${baseUrl}/${channel}`,
// each feed item
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/ekantipur/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:channel?': ['maniche04'],
};
13 changes: 13 additions & 0 deletions lib/v2/ekantipur/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'ekantipur.com': {
_name: 'Ekantipur',
'.': [
{
title: 'Full Article RSS',
docs: 'https://docs.rsshub.app/routes/traditional-media#ekantipur-%E0%A4%95%E0%A4%BE%E0%A4%A8%E0%A5%8D%E0%A4%A4%E0%A4%BF%E0%A4%AA%E0%A5%81%E0%A4%B0-nepal',
source: ['/:channel'],
target: '/ekantipur/:channel',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ekantipur/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:channel?', require('./issue'));
};
34 changes: 34 additions & 0 deletions lib/v2/huggingface/blog-zh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { body: response } = await got('https://huggingface.co/blog/zh');
const $ = cheerio.load(response);

/** @type {Array<{blog: {local: string, title: string, author: string, thumbnail: string, date: string, tags: Array<string>}, blogUrl: string, lang: 'zh', link: string}>} */
const papers = $('div[data-target="BlogThumbnail"]')
.toArray()
.map((item) => {
const props = $(item).data('props');
const link = $(item).find('a').attr('href');
return {
...props,
link,
};
});

const items = papers.map((item) => ({
title: item.blog.title,
link: `https://huggingface.co${item.link}`,
category: item.blog.tags,
pubDate: parseDate(item.blog.date),
author: item.blog.author,
}));

ctx.state.data = {
title: 'Huggingface 中文博客',
link: 'https://huggingface.co/blog/zh',
item: items,
};
};
1 change: 1 addition & 0 deletions lib/v2/huggingface/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/blog-zh': ['zcf0508'],
'/daily-papers': ['zeyugao'],
};
6 changes: 6 additions & 0 deletions lib/v2/huggingface/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ module.exports = {
source: ['/papers', '/'],
target: '/huggingface/daily-papers',
},
{
title: '中文博客',
docs: 'https://docs.rsshub.app/routes/programming#huggingface',
source: ['/blog/zh', '/'],
target: '/huggingface/blog-zh',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/huggingface/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = (router) => {
router.get('/blog-zh', require('./blog-zh'));
router.get('/daily-papers', require('./daily-papers'));
};
3 changes: 3 additions & 0 deletions lib/v2/onet/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/news': ['Vegann'],
};
Loading

0 comments on commit cb4e0ab

Please sign in to comment.