-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
base: master
Are you sure you want to change the base?
Changes from 15 commits
f272ce1
6a8e383
52f797c
3c57eec
8a1eb1d
2583504
46eebb0
31d78af
1fd79d2
5c0985a
46c870d
ab573d9
0a722ea
de3f6fc
e18d6f7
62caf6f
a13fad6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,101 @@ | ||||||||||||||||
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: '', | ||||||||||||||||
categories: ['bbs'], | ||||||||||||||||
example: '/guozaoke', | ||||||||||||||||
parameters: {}, | ||||||||||||||||
features: { | ||||||||||||||||
requireConfig: false, | ||||||||||||||||
requirePuppeteer: false, | ||||||||||||||||
antiCrawler: true, | ||||||||||||||||
supportBT: false, | ||||||||||||||||
supportPodcast: false, | ||||||||||||||||
supportScihub: false, | ||||||||||||||||
}, | ||||||||||||||||
name: 'guozaoke', | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Route name should not be the same as namespace name. |
||||||||||||||||
maintainers: ['xiaoshame'], | ||||||||||||||||
handler, | ||||||||||||||||
url: 'guozaoke.com/', | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
async function getContent(link) { | ||||||||||||||||
return await cache.tryGet(link, async () => { | ||||||||||||||||
const url = `https://www.guozaoke.com${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; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return content; | ||||||||||||||||
}); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
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 = []; | ||||||||||||||||
for await (const data of asyncPool(1, list.slice(0, maxItems), async (i) => { | ||||||||||||||||
const $item = $(i); | ||||||||||||||||
const title = $item.find('h3.title a').text(); | ||||||||||||||||
const link = $item.find('h3.title a').attr('href'); | ||||||||||||||||
xiaoshame marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
const author = $item.find('span.username a').text(); | ||||||||||||||||
const lastTouched = $item.find('span.last-touched').text(); | ||||||||||||||||
const time = parseRelativeDate(lastTouched); | ||||||||||||||||
const description = await getContent(link); | ||||||||||||||||
return { | ||||||||||||||||
title, | ||||||||||||||||
description, | ||||||||||||||||
author, | ||||||||||||||||
link: link.split('#')[0], | ||||||||||||||||
pubDate: time, | ||||||||||||||||
}; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
#17170 (comment) is commented on lines 89 to 95 so the returned object is expected to have RSSHub/lib/routes/guozaoke/index.ts Lines 85 to 91 in e18d6f7
|
||||||||||||||||
})) { | ||||||||||||||||
items.push(data); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return { | ||||||||||||||||
title: '过早客', | ||||||||||||||||
link: url, | ||||||||||||||||
item: items, | ||||||||||||||||
}; | ||||||||||||||||
} |
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', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path
cannot be empty