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

feat(route): add bbs guozaoke route #17170

Merged
merged 25 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f272ce1
add routes guozaoke
xiaoshame Oct 17, 2024
6a8e383
add routes guozaoke
xiaoshame Oct 17, 2024
52f797c
Merge branch 'master' of github.com:xiaoshame/RSSHub
xiaoshame Oct 17, 2024
3c57eec
fix ESLint Check warning
xiaoshame Oct 17, 2024
8a1eb1d
fix ESLint Check warning
xiaoshame Oct 17, 2024
2583504
fix ESLint Check warning
xiaoshame Oct 17, 2024
46eebb0
fix ESLint Check warning
xiaoshame Oct 17, 2024
31d78af
fix ESLint Check warning
xiaoshame Oct 17, 2024
1fd79d2
Merge branch 'DIYgod:master' into master
xiaoshame Oct 25, 2024
5c0985a
fix routes guozaoke code review
xiaoshame Oct 25, 2024
46c870d
Merge branch 'DIYgod:master' into master
xiaoshame Oct 25, 2024
ab573d9
fix routes guozaoke code review
xiaoshame Oct 25, 2024
0a722ea
Merge branch 'master' of github.com:xiaoshame/RSSHub
xiaoshame Oct 25, 2024
de3f6fc
fix route code review
xiaoshame Oct 25, 2024
e18d6f7
fix code revice issue
xiaoshame Oct 25, 2024
62caf6f
Merge branch 'DIYgod:master' into master
xiaoshame Oct 28, 2024
a13fad6
fix code revice issue
xiaoshame Oct 28, 2024
6c1909f
fix code revice issue
xiaoshame Oct 28, 2024
7f89220
fix code revice issue
xiaoshame Oct 28, 2024
556704c
fix code revice issue
xiaoshame Oct 28, 2024
90a6ffe
fix code revice issue
xiaoshame Oct 28, 2024
9757e3d
Merge branch 'DIYgod:master' into master
xiaoshame Oct 29, 2024
ef5050f
fix code review issues
xiaoshame Oct 29, 2024
6664235
Merge branch 'DIYgod:master' into master
xiaoshame Oct 30, 2024
135b9d3
fix code review issues
xiaoshame Oct 30, 2024
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
6 changes: 6 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ export type Config = {
google: {
fontsApiKey?: string;
};
guozaoke: {
cookies?: string;
};
hefeng: {
key?: string;
};
Expand Down Expand Up @@ -550,6 +553,9 @@ const calculateValue = () => {
google: {
fontsApiKey: envs.GOOGLE_FONTS_API_KEY,
},
guozaoke: {
cookies: envs.GUOZAOKE_COOKIES,
},
hefeng: {
// weather
key: envs.HEFENG_KEY,
Expand Down
99 changes: 99 additions & 0 deletions lib/routes/guozaoke/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseRelativeDate } from '@/utils/parse-date';
import { config } from '@/config';
import cache from '@/utils/cache';
import asyncPool from 'tiny-async-pool';

export const route: Route = {
path: '/default',
categories: ['bbs'],
example: '/guozaoke/default',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '过早客',
maintainers: ['xiaoshame'],
handler,
url: 'guozaoke.com/',
};

async function handler() {
const url = 'https://www.guozaoke.com/';
const res = await got({
method: 'get',
url,
headers: {
Cookie: config.guozaoke.cookies,
'User-Agent': config.ua,
},
});
const $ = load(res.data);

const list = $('div.topic-item').toArray();
const maxItems = 20; // 最多取20个数据

const items = list
.slice(0, maxItems)
.map((item) => {
const $item = $(item);
const title = $item.find('h3.title a').text();
const url = $item.find('h3.title a').attr('href');
const author = $item.find('span.username a').text();
const lastTouched = $item.find('span.last-touched').text();
const time = parseRelativeDate(lastTouched);
const link = url ? url.split('#')[0] : undefined;
return link ? { title, link, author, time } : undefined;
})
.filter((item) => item !== undefined);

const out = [];
for await (const result of asyncPool(2, items, (item) =>
cache.tryGet(item.link, async () => {
const url = `https://www.guozaoke.com${item.link}`;
const res = await got({
method: 'get',
url,
headers: {
Cookie: config.guozaoke.cookies,
'User-Agent': config.ua,
},
});

const $ = load(res.data);
let content = $('div.ui-content').html();
content = content ? content.trim() : '';
const comments = $('.reply-item').map((i, el) => {
const $el = $(el);
const comment = $el.find('span.content').text().trim();
const author = $el.find('span.username').text();
return {
comment,
author,
};
});
if (comments && comments.length > 0) {
for (const item of comments) {
content += '<br>' + item.author + ': ' + item.comment;
}
}
item.description = content;
return item;
})
)) {
out.push(result);
}

return {
title: '过早客',
link: url,
item: out,
};
}
6 changes: 6 additions & 0 deletions lib/routes/guozaoke/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'guozaoke',
url: 'guozaoke.com',
};
Loading