diff --git a/docs/shopping.md b/docs/shopping.md index 1fdcfa7161..ef87cfac69 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -42,6 +42,16 @@ For instance, in https://www.leboncoin.fr/recherche/?**category=10&locations=Par +## 好好住 + +### 整屋案例 + + + +### 发现 + + + ## 京东众筹 ### 众筹项目 diff --git a/lib/router.js b/lib/router.js index f9f7611fde..769396c8d5 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2233,6 +2233,10 @@ router.get('/2048/bbs/:fid', require('./routes/2048/bbs')); // Google News router.get('/google/news/:category/:locale', require('./routes/google/news')); +// 好好住 +router.get('/haohaozhu/whole-house/:keyword?', require('./routes/haohaozhu/whole-house')); +router.get('/haohaozhu/discover/:keyword?', require('./routes/haohaozhu/discover')); + // 东北大学 router.get('/neu/news/:type', require('./routes/universities/neu/news')); diff --git a/lib/routes/haohaozhu/discover.js b/lib/routes/haohaozhu/discover.js new file mode 100644 index 0000000000..ebc681327b --- /dev/null +++ b/lib/routes/haohaozhu/discover.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const keyword = ctx.params.keyword && ctx.params.keyword !== 'all' && ctx.params.keyword !== '全部' ? ctx.params.keyword : ''; + + const url = 'https://www.haohaozhu.cn/community/discover'; + + const response = await got({ + method: 'post', + url: 'https://www.haohaozhu.cn/f/y/api/Share/AllPhotoInPc', + headers: { + Referer: url, + }, + form: { + keyword: keyword, + page: 1, + time: new Date().getTime(), + }, + }); + + const list = response.data.data.rows; + + ctx.state.data = { + title: `好好住 - 发现${keyword ? ' - ' + keyword : ''}`, + link: url, + item: list + .map((item) => { + if (item.is_advertisement !== 0 || !item.photo || !item.photo.photo_info) { + return ''; + } + return { + title: item.photo.photo_info.remark, + author: item.photo.user_info.nick, + description: item.photo.photo_info.image_list.map((image) => ``).join(''), + link: url, + guid: item.photo.photo_info.id, + pubDate: new Date(item.photo.photo_info.addtime * 1000), + }; + }) + .filter((item) => item !== ''), + }; +}; diff --git a/lib/routes/haohaozhu/whole-house.js b/lib/routes/haohaozhu/whole-house.js new file mode 100644 index 0000000000..921ccbf576 --- /dev/null +++ b/lib/routes/haohaozhu/whole-house.js @@ -0,0 +1,75 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const keyword = ctx.params.keyword && ctx.params.keyword !== 'all' && ctx.params.keyword !== '全部' ? ctx.params.keyword : ''; + + const url = 'https://www.haohaozhu.cn/community/whole-house'; + + const response = await got({ + method: 'post', + url: 'https://www.haohaozhu.cn/f/y/api/Share/GetArticle', + headers: { + Referer: url, + }, + form: { + keyword: keyword, + page: 1, + }, + }); + + const list = response.data.data.rows; + + const parseContent = (htmlString) => { + const $ = cheerio.load(htmlString); + + const content = $('.whole-header').parent(); + $('.whole-title').remove(); + $('.whole-user').remove(); + $('.question').appendTo(content); + + return { + description: content.html(), + }; + }; + + const out = await Promise.all( + list.map(async (item, index) => { + const link = `https://www.haohaozhu.cn/community/whole-house-detail/${item.article_id}`; + + const time = new Date(); + time.setMinutes(time.getMinutes() - index); + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const rssitem = { + title: item.article_info.title, + link: link, + author: item.user_info.nick, + pubDate: time, + }; + + try { + const response = await got.get(link); + const result = parseContent(response.data); + if (!result.description) { + return Promise.resolve(''); + } + rssitem.description = result.description; + } catch (err) { + return Promise.resolve(''); + } + ctx.cache.set(link, JSON.stringify(rssitem)); + return Promise.resolve(rssitem); + }) + ); + + ctx.state.data = { + title: `好好住 - 整屋案例${keyword ? ' - ' + keyword : ''}`, + link: url, + item: out.filter((item) => item !== ''), + }; +};