fix: fix whunews, add pmcaff, fix #4268 (#4266)

This commit is contained in:
SChen00
2020-03-19 18:11:42 +08:00
committed by GitHub
parent 28c3545cf9
commit f5b500e8ab
10 changed files with 203 additions and 28 deletions

View File

@@ -249,6 +249,12 @@ pageClass: routes
<Route author="luyuhuang" example="/3ycy/home" path="/3ycy/home" radar="1"/>
## 紳士漫畫
### 最新
<Route author="KenMizz" example="/ssmh" path="/ssmh/">
## 鼠绘漫画
### 鼠绘漫画
@@ -266,9 +272,3 @@ pageClass: routes
### 最新汉化
<Route author="junfengP" example="/zdfx" path="/zdfx"/>
## 紳士漫畫
### 最新
<Route author="KenMizz" example="/ssmh" path="/ssmh/">

View File

@@ -10,6 +10,16 @@ pageClass: routes
<Route author="HenryQW" example="/finviz/news/AAPL" path="/finviz/news/:ticker" :paramsDesc="['股票代码']"/>
## WEEX 华尔街见闻旗下全球投资线上品牌
### 资讯
<Route author="SChen1024" example="/weexcn/news/1" path="/weexcn/news/:typeid" :paramsDesc="['栏目代码, 按照表列出']">
| 最新文章 | 市场要闻 | 交易策略 | 机构观点 | 投资学堂 | 行业观察 | 基金理财 | 分析师投稿 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | ---------- |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
## 淘股吧股票论坛
### 论坛总版
@@ -20,6 +30,12 @@ pageClass: routes
<Route author="emdoe" example="/taoguba/user/252069" path="/taoguba/user/:uid" :paramsDesc="['用户 id']" />
## 天天基金
### 用户动态
<Route author="zidekuls" example="/eastmoney/user/6551094298949188" path="/eastmoney/user/:uid" :paramsDesc="['用户 id, 可在用户主页 URL 中找到']"/>
## 雪球
### 用户动态
@@ -57,9 +73,3 @@ pageClass: routes
| announcement | news | research |
</Route>
## 天天基金
### 用户动态
<Route author="zidekuls" example="/eastmoney/user/6551094298949188" path="/eastmoney/user/:uid" :paramsDesc="['用户 id, 可在用户主页 URL 中找到']"/>

View File

@@ -195,6 +195,10 @@ pageClass: routes
| ---- | ------ | ---- | -------- | ---- | ---- | ---- |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
### 用户文章
<Route author="SChen1024" example="/pmcaff/user/Oak7mqnEQJ" path="/pmcaff/user/:userid" :paramsDesc="['用户 id, 用户界面对应的 URL 最后面的字符']"/>
## Quanta Magazine
### 全部

View File

@@ -284,6 +284,12 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="xapool" example="/aqicn/beijing" path="/aqicn/:city" :paramsDesc="['城市拼音或地区 ID详见[aqicn.org](http://aqicn.org/city/)']"/>
## 酷安
### 图文-编辑精选
<Route author="xizeyoupan" example="/coolapk/tuwen" path="/coolapk/tuwen" />
## 快递 100
### 快递订单追踪
@@ -601,9 +607,3 @@ type 为 all 时category 参数不支持 cost 和 free
### はてな匿名ダイアリー - 人気記事アーカイブ
<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>
## 酷安
### 图文-编辑精选
<Route author="xizeyoupan" example="/coolapk/tuwen" path="/coolapk/tuwen" />

View File

@@ -1136,7 +1136,6 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet
| 综合新闻 | zhxw |
| 珞珈影像 | ljyx |
| 学术动态 | kydt |
| 点击排行 | djpx |
| 珞珈副刊 | ljfk |
| 校史钩沉 | xsgc |
| 来稿选登 | lgxd |

View File

@@ -225,6 +225,9 @@ router.get('/jiemian/list/:cid', require('./routes/jiemian/list.js'));
// 好奇心日报
router.get('/qdaily/:type/:id', require('./routes/qdaily/index'));
// WEEX
router.get('/weexcn/news/:typeid', require('./routes/weexcn/index'));
// 爱奇艺
router.get('/iqiyi/dongman/:id', require('./routes/iqiyi/dongman'));
router.get('/iqiyi/user/video/:uid', require('./routes/iqiyi/video'));
@@ -1088,6 +1091,7 @@ router.get('/36kr/newsflashes', require('./routes/36kr/newsflashes'));
// PMCAFF
router.get('/pmcaff/list/:typeid', require('./routes/pmcaff/list'));
router.get('/pmcaff/feed/:typeid', require('./routes/pmcaff/feed'));
router.get('/pmcaff/user/:userid', require('./routes/pmcaff/user'));
// icourse163
router.get('/icourse163/newest', require('./routes/icourse163/newest'));

56
lib/routes/pmcaff/user.js Normal file
View File

@@ -0,0 +1,56 @@
const got = require('@/utils/got');
// 样例 链接 : https://www.pmcaff.com/user/profile/Oak7mqnEQJ
const baseUrl = 'https://www.pmcaff.com/user/profile/';
const api_url = 'https://api.pmcaff.com/api/v0/user/user-articles/';
const sizeTitle = 'PMCAFF互联网产品社区';
// 参考 feed.js
module.exports = async (ctx) => {
// 默认 用户 id Oak7mqnEQJ
const userid = ctx.params.userid || 'Oak7mqnEQJ';
const user_article = api_url + userid;
// 直接获取到 json 数据
const response = await got({
method: 'get',
url: user_article,
headers: {
Referer: baseUrl,
},
});
let user_name = '';
const result = [];
response.data.data.map(async (item) => {
const title = item.title;
const guid = item.article_id;
const pubDate = new Date(item.ctime).toUTCString();
const link = item.target_url;
const description = item.content;
const single = {
title: title,
link: link,
guid: guid,
pubDate: pubDate,
description: description,
};
// 更新用户名
user_name = item.user_profile.name;
result.push(single);
});
ctx.state.data = {
title: user_name + '---' + sizeTitle,
link: baseUrl + userid,
description: 'PMCAFF互联网产品社区 - 产品经理人气组织::专注于互联网产品研究',
item: result,
};
};

View File

@@ -1,10 +1,11 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
// const url = require('url');
// 参考 bit/jwc 北京理工大学的的页面写成
const baseUrl = 'https://news.whu.edu.cn/';
const sizeTitle = '武汉大学新闻网';
const sizeTitle = '--武汉大学新闻网';
const catrgoryMap = {
wdyw: '武大要闻',
@@ -20,7 +21,6 @@ const catrgoryMap = {
zhxw: '综合新闻',
ljyx: '珞珈影像',
kydt: '学术动态',
djpx: '点击排行',
ljfk: '珞珈副刊',
xsgc: '校史钩沉',
lgxd: '来稿选登',
@@ -28,8 +28,28 @@ const catrgoryMap = {
// 专门定义一个function用于加载文章内容
async function load(link) {
// 异步请求文章
const response = await got.get(link);
let description = '';
let pubDate = '';
let response;
// 如果不是 武汉大学的站点, 直接返回简单的标题即可
// 判断 是否外站链接,如果是 则直接返回页面 不做单独的解析
const https_reg = new RegExp('https://news.whu.edu.cn(.*)');
if (!https_reg.test(link)) {
return { description };
}
// 外部链接访问不到不处理, 校内页面访问不到 记录错误
try {
// 异步请求文章
response = await got.get(link);
} catch (err) {
// 如果网络问题 直接出错
if (err.name && (err.name === 'HTTPError' || err.name === 'RequestError')) {
description = 'Page 404 Please Check!';
}
return { description };
}
// 加载文章内容
const $ = cheerio.load(response.data);
@@ -37,10 +57,12 @@ async function load(link) {
const date_txt = $('div.news_attrib')
.text()
.match(/[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d/); // 匹配 yyyy-mm-dd hh:MM 格式时间
const pubDate = new Date(date_txt[0]);
// console.log(link,":",date_txt);
pubDate = new Date(date_txt[0]);
// 提取文章内容
const description = $('div.v_news_content').html();
description = $('div.v_news_content').html();
// 返回解析的结果
return { description, pubDate };
}
@@ -68,14 +90,25 @@ module.exports = async (ctx) => {
.map(async (item) => {
const $ = cheerio.load(list[item]); // 将列表项加载成 html
const $rel_url = $('div.infotitle>a').attr('href'); // 获取 每一项的url
const $item_url = baseUrl + $rel_url; // 获取绝对路径
// 判断是否相对链接 然后改写绝对路径 http 默认 否则加上基础路径
const https_reg = new RegExp('^(?:[a-z]+:)?//');
const $item_url = https_reg.test($rel_url) ? $rel_url : baseUrl + $rel_url;
const $title = $('div>a').attr('title'); // 获取每个的标题
const $pubdate = new Date(
$('div.infodate')
.text()
.trim()
// .match('/[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s/')[0]
);
// console.log(item, ":", $item_url,":",$pubdate);
// 列表上提取到的信息
// 标题 链接
const single = {
title: $title,
// pubDate: $pubdate,
pubDate: $pubdate,
link: $item_url,
guid: $item_url,
};

View File

@@ -0,0 +1,69 @@
const got = require('@/utils/got');
// 样例 链接 : https://weexcn.com/news/newest
const baseUrl = 'https://weexcn.com/news/';
// const api_url = 'https://api.jianyuweb.com/apiv1/content/articles?category=&limit=15&cursor=&platform=weex-platform';
const sizeTitle = 'WEEX--华尔街见闻旗下全球投资线上品牌';
// 数字标识, name 栏目名称, link: url, category: api cate
const map = new Map([
['1', { name: '最新文章', link: 'newest', category: '' }],
['2', { name: '市场要闻', link: 'important', category: 'weex-important' }],
['3', { name: '交易策略', link: 'strategy', category: 'weex-tradingstrategies' }],
['4', { name: '机构观点', link: 'opinion', category: 'weex-institutioncomments' }],
['5', { name: '投资学堂', link: 'education', category: 'weex-introduction' }],
['6', { name: '行业观察', link: 'industry', category: 'weex-industryanalysis' }],
['7', { name: '基金理财', link: 'money', category: 'weex-money' }],
['7', { name: '分析师投稿', link: 'analyst', category: 'weex-analyst' }],
]);
module.exports = async (ctx) => {
// 默认 用户 id Oak7mqnEQJ
const type_id = ctx.params.typeid || '1';
const type = map.get(type_id);
const type_url = 'https://weexcn.com/news/' + type.link;
const type_api_url = `https://api.jianyuweb.com/apiv1/content/articles?category=${type.category}&limit=15&cursor=&platform=weex-platform`;
// 直接获取到 json 数据
const response = await got({
method: 'get',
url: type_api_url,
headers: {
Referer: type_url,
},
});
const json_data = response.data.data.items;
const result = [];
json_data.map(async (item) => {
const title = item.title;
const guid = item.id;
const pubDate = new Date(item.display_time * 1000).toUTCString();
// link 需要转换
// https://wallstreetcn.com/articles/3587433
// https://weexcn.com/articles/3587433
const link = item.uri.replace(/wallstreetcn.com/, 'weexcn.com');
const description = item.content_short;
const single = {
title: title,
link: link,
guid: guid,
pubDate: pubDate,
description: description,
};
result.push(single);
});
ctx.state.data = {
title: type.name + '---' + sizeTitle,
link: baseUrl + type.link,
description: sizeTitle,
item: result,
};
};