From 3b2095f27d87cd74b64c22f4ee3ebc931d3f06bb Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 11 Apr 2018 18:33:41 +0800 Subject: [PATCH] ziroom module --- index.js | 3 +++ routes/ziroom/room.js | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 routes/ziroom/room.js diff --git a/index.js b/index.js index e78acb6e9c..7059c8d9d5 100644 --- a/index.js +++ b/index.js @@ -24,4 +24,7 @@ app.get('/ncm/playlist/:id', require('./routes/ncm/playlist')); // 掘金 app.get('/juejin/category/:category', require('./routes/juejin/category')); +// 自如 +app.get('/ziroom/room/:city/:iswhole/:room/:keyword', require('./routes/ziroom/room')); + app.listen(1200); \ No newline at end of file diff --git a/routes/ziroom/room.js b/routes/ziroom/room.js new file mode 100644 index 0000000000..eb46b6850b --- /dev/null +++ b/routes/ziroom/room.js @@ -0,0 +1,57 @@ +const request = require('request'); +const art = require('art-template'); +const path = require('path'); +const base = require('../base'); +const mix = require('../../utils/mix'); + +module.exports = (req, res) => { + const city = req.params.city || 'sh'; + const keyword = req.params.keyword || ''; + const iswhole = req.params.iswhole || 0; + const room = req.params.room || 1; + const domain = `${city === 'bj' ? '' : city + '.'}m.ziroom.com`; + + base({ + req: req, + res: res, + getHTML: (callback) => { + request.post({ + url: `http://${domain}/list/ajax-get-data`, + headers: { + 'User-Agent': mix.ua, + 'Referer': `http://${domain}/${city.toUpperCase()}/search.html` + }, + form: { + 'recent_money': 0, + 'sort': 0, + 'is_whole': iswhole, + 'room': room, + 'key_word': keyword, + 'step': 0 + } + }, (err, httpResponse, body) => { + let data; + try { + data = JSON.parse(body); + } + catch (e) { + data = {}; + } + const result = data.data || []; + + const html = art(path.resolve(__dirname, '../../views/rss.art'), { + title: `自如的${keyword}${iswhole ? '整租' : '合租'}${room}室房源`, + link: `http://${domain}`, + description: `自如的${keyword}${iswhole ? '整租' : '合租'}${room}室房源`, + lastBuildDate: new Date().toUTCString(), + item: result && result.map((item) => ({ + title: item.title, + description: `${item.room_name}`, + link: `http://${domain}/${city.toUpperCase()}/room/${item.id}.html` + })), + }); + callback(html); + }); + } + }); +}; \ No newline at end of file