Skip to content

Commit

Permalink
Merge pull request #5 from DIYgod/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
CoderTonyChan committed Feb 13, 2019
2 parents f68ebca + 4fde0e1 commit 06afd64
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 15 deletions.
7 changes: 7 additions & 0 deletions docs/README.md
Expand Up @@ -475,6 +475,8 @@ RSSHub 提供下列 API 接口:

<route name="浏览发现" author="clarkzsd" example="/douban/explore" path="/douban/explore"/>

<route name="浏览发现分栏目" author="LogicJake" example="/douban/explore/column/2" path="/douban/explore_column/:id" :paramsDesc="['分栏目id']"/>

<route name="新书速递" author="fengkx" example="/douban/book/latest" path="douban/book/latest"/>

<route name="最新增加的音乐" author="fengkx xyqfer" example="/douban/music/latest/chinese" path="/douban/music/latest/:area?" :paramsDesc="['区域类型,默认全部']">
Expand Down Expand Up @@ -2898,3 +2900,8 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 加摩根大通研究所

<route name="新闻" author="howel.52" example="/jpmorganchase" path="/jpmorganchase"/>

### 人人都是产品经理

<route name="用户收藏" author="LogicJake" example="/woshipm/bookmarks/324696" path="/woshipm/bookmarks/:id" :paramsDesc="['用户id']"/>
<route name="用户文章" author="LogicJake" example="/woshipm/user_article/324696" path="/woshipm/user_article/:id" :paramsDesc="['用户id']"/>
5 changes: 5 additions & 0 deletions lib/router.js
Expand Up @@ -228,6 +228,7 @@ router.get('/douban/commercialpress/latest', require('./routes/douban/commercial
router.get('/douban/bookstore', require('./routes/douban/bookstore'));
router.get('/douban/book/rank/:type', require('./routes/douban/book/rank'));
router.get('/douban/doulist/:id', require('./routes/douban/doulist'));
router.get('/douban/explore/column/:id', require('./routes/douban/explore_column'));

// 煎蛋
router.get('/jandan/:sub_model', require('./routes/jandan/pic'));
Expand Down Expand Up @@ -1039,6 +1040,10 @@ router.get('/jpmorganchase', require('./routes/jpmorganchase/research'));
// 美拍
router.get('/meipai/user/:uid', require('./routes/meipai/user'));

// 人人都是产品经理
router.get('/woshipm/bookmarks/:id', require('./routes/woshipm/bookmarks'));
router.get('/woshipm/user_article/:id', require('./routes/woshipm/user_article'));

// 高清电台
router.get('/gaoqing/latest', require('./routes/gaoqing/latest'));

Expand Down
30 changes: 20 additions & 10 deletions lib/routes/dongqiudi/daily.js
@@ -1,6 +1,7 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const utils = require('./utils');
const date = require('../../utils/date');

module.exports = async (ctx) => {
const response = await axios.get('https://www.dongqiudi.com/special/48');
Expand All @@ -10,7 +11,7 @@ module.exports = async (ctx) => {
const host = 'https://www.dongqiudi.com';

const list = $('.detail.special ul li h3')
.slice(0, 10)
.slice(0, 5)
.get();

const proList = [];
Expand All @@ -21,18 +22,19 @@ module.exports = async (ctx) => {
const title = $('a').text();
const itemUrl = host + $('a').attr('href');

const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

const single = {
title,
link: itemUrl,
};

try {
const es = axios.get(itemUrl);
proList.push(es);
return Promise.resolve(single);
} catch (err) {
console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`);
}
const es = axios.get(itemUrl);
proList.push(es);
return Promise.resolve(single);
})
);

Expand All @@ -43,11 +45,19 @@ module.exports = async (ctx) => {

out[i].description = utils.ProcessHref(full.find('div:nth-of-type(1)')).html();
out[i].author = full.find('span.name').text();
out[i].pubDate = new Date(full.find('span.time').text()).toUTCString();
out[i].pubDate = date(
full
.find('span.time')
.text()
.trim(),
8
);

ctx.cache.set(out[i].itemUrl, JSON.stringify(out[i]), 24 * 60 * 60);
}
ctx.state.data = {
title: '懂球帝早报',
link: 'http://www.dongqiudi.com/special/48',
item: out,
item: out.filter((e) => e !== undefined),
};
};
56 changes: 56 additions & 0 deletions lib/routes/douban/explore_column.js
@@ -0,0 +1,56 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');

const host = 'https://www.douban.com/explore/column/';
module.exports = async (ctx) => {
const id = ctx.params.id;
const link = url.resolve(host, id);
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('div.h1').text();

const list = $('div.item')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('div.title a')
.text(),
link: $(this)
.find('div.title a')
.attr('href'),
author: $(this)
.find('div.usr-pic a')
.text(),
};
return info;
})
.get();

const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const author = info.author;
const itemUrl = info.link;

const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('#link-report').html();

const single = {
title: title,
link: itemUrl,
description: description,
author: author,
};
return Promise.resolve(single);
})
);

ctx.state.data = {
title: `${title}-豆瓣发现`,
link: link,
item: out,
};
};
47 changes: 47 additions & 0 deletions lib/routes/woshipm/bookmarks.js
@@ -0,0 +1,47 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const id = ctx.params.id;
const link = `http://www.woshipm.com/u/${id}`;
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const name = $('div.name').text();

const remark_api = `http://www.woshipm.com/__api/v1/users/${id}/bookmarks`;
const response_api = await axios.get(remark_api);
const list = response_api.data.payload.value;
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = info.permalink;

const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('div.grap')
.html()
.trim();

const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);

ctx.state.data = {
title: `${name}的收藏-人人都是产品经理`,
link: link,
item: out,
};
};
63 changes: 63 additions & 0 deletions lib/routes/woshipm/user_article.js
@@ -0,0 +1,63 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const id = ctx.params.id;
const link = `http://www.woshipm.com/u/${id}`;

const response = await axios.get(link);
const $ = cheerio.load(response.data);

const name = $('div.name').text();
const list = $('div.postlist-item.u-clearfix div.content')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('h2.post-title a')
.attr('title'),
link: $(this)
.find('h2.post-title a')
.attr('href'),
date: $(this)
.find('time')
.text(),
};
return info;
})
.get();

const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = info.link;

const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('div.grap')
.html()
.trim();

const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
return Promise.resolve(single);
})
);

ctx.state.data = {
title: `${name}的文章-人人都是产品经理`,
link: link,
item: out,
};
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -54,7 +54,7 @@
"dayjs": "^1.7.7",
"form-data": "^2.3.2",
"git-rev-sync": "1.12.0",
"googleapis": "37.1.0",
"googleapis": "37.2.0",
"he": "^1.1.1",
"iconv-lite": "0.4.24",
"imgur": "^0.3.1",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -4306,10 +4306,10 @@ googleapis-common@^0.7.0:
url-template "^2.0.8"
uuid "^3.2.1"

googleapis@37.1.0:
version "37.1.0"
resolved "https://registry.yarnpkg.com/googleapis/-/googleapis-37.1.0.tgz#34a663179ea5a1b290b7af1ea1a1ae9a9eabfcb0"
integrity sha512-ajQF/BA95pCknQWtNFelcSuwZpiUKyKlfbEFd/q3gWMWJWlkMd4Bb+oI6+A0lQ0spqQF/zzMyviTiLCaws5hkw==
googleapis@37.2.0:
version "37.2.0"
resolved "https://registry.yarnpkg.com/googleapis/-/googleapis-37.2.0.tgz#63bfcadaccc7cb8c1d8dff90573c48ca18132409"
integrity sha512-UenlZ0c4eaVAylIPvvsIlL/q5/3Xg8DuKug5aqdmRMk+tTVfJUmEKgp3s4ZSUOI5oKqO/+arIW5UnY2S62B13w==
dependencies:
google-auth-library "^3.0.0"
googleapis-common "^0.7.0"
Expand Down

0 comments on commit 06afd64

Please sign in to comment.