Skip to content

Commit

Permalink
Merge pull request #891 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Mar 25, 2023
2 parents 37fcbbc + 294e690 commit 4b42edf
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 117 deletions.
18 changes: 18 additions & 0 deletions docs/programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,24 @@ GitHub 官方也提供了一些 RSS:

</Route>

## ModelScope 魔搭社区

### 数据集

<Route author="TonyRL" example="/modelscope/datasets" path="/modelscope/datasets" radar="1" />

### 模型库

<Route author="TonyRL" example="/modelscope/models" path="/modelscope/models" radar="1" />

### 创空间

<Route author="TonyRL" example="/modelscope/studios" path="/modelscope/studios" radar="1" />

### DevPress 官方社区

<Route author="TonyRL" example="/modelscope/community" path="/modelscope/community" radar="1" />

## MySQL

### Release Notes
Expand Down
30 changes: 24 additions & 6 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,31 @@ Category 列表:

## 参考消息

### 新闻分类

<Route author="yuxinliu-alex" example="/cankaoxiaoxi/news/military_news" path="/cankaoxiaoxi/news/:category">
### 栏目

| 中国 | 国际 | 军事 | 台海 | 财经 | 科技 | 文化 |
| ---------- | ---------- | ------------- | ----------- | ------------ | --------------- | ------------ |
| china_news | world_news | military_news | taiwan_news | finance_news | technology_news | culture_news |
<Route author="yuxinliu-alex nczitzk" example="/cankaoxiaoxi/column/diyi" path="/cankaoxiaoxi/column/:id?" :paramsDesc="['栏目 id,默认为 diyi,即第一关注']">

| 栏目 | id |
| -------------- | -------- |
| 第一关注 | diyi |
| 中国 | zhongguo |
| 国际 | gj |
| 观点 | guandian |
| 锐参考 | ruick |
| 体育健康 | tiyujk |
| 科技应用 | kejiyy |
| 文化旅游 | wenhualy |
| 参考漫谈 | cankaomt |
| 研究动态 | yjdt |
| 海外智库 | hwzk |
| 业界信息・观点 | yjxx |
| 海外看中国城市 | hwkzgcs |
| 译名趣谈 | ymymqt |
| 译名发布 | ymymfb |
| 双语汇 | ymsyh |
| 参考视频 | video |
| 军事 | junshi |
| 参考人物 | cankaorw |

</Route>

Expand Down
101 changes: 44 additions & 57 deletions lib/v2/cankaoxiaoxi/index.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,65 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const cheerio = require('cheerio');

const nodes = {
china_news: {
title: '中国',
url: 'https://china.cankaoxiaoxi.com/',
},
world_news: {
title: '国际',
url: 'https://world.cankaoxiaoxi.com/',
},
military_news: {
title: '军事',
url: 'https://mil.cankaoxiaoxi.com/',
},
taiwan_news: {
title: '台海',
url: 'https://tw.cankaoxiaoxi.com/',
},
finance_news: {
title: '财经',
url: 'https://finance.cankaoxiaoxi.com/',
},
technology_news: {
title: '科技',
url: 'https://science.cankaoxiaoxi.com/',
},
culture_news: {
title: '文化',
url: 'https://culture.cankaoxiaoxi.com/',
},
};
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const category = ctx.params.category;
const id = ctx.params.id ?? 'diyi';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;

const currentUrl = nodes[category].url;
const response = await got({
const rootUrl = 'https://china.cankaoxiaoxi.com';
const listApiUrl = `${rootUrl}/json/channel/${id}/list.json`;
const channelApiUrl = `${rootUrl}/json/channel/${id}.channeljson`;
const currentUrl = `${rootUrl}/#/generalColumns/${id}`;

const listResponse = await got({
method: 'get',
url: currentUrl,
url: listApiUrl,
});

const $ = cheerio.load(response.data);
const channelResponse = await got({
method: 'get',
url: channelApiUrl,
});

const list = $('a', '.toutiao')
.filter(function () {
return $(this).text() !== '';
})
.map((_, item) => ({
link: $(item).attr('href'),
}))
.get();
let items = listResponse.data.list.slice(0, limit).map((item) => ({
title: item.data.title,
author: item.data.userName,
category: item.data.channelName,
pubDate: timezone(parseDate(item.data.publishTime), +8),
link: item.data.moVideoPath ? item.data.sourceUrl : `${rootUrl}/json/content/${item.data.url.match(/\/pages\/(.*?)\.html/)[1]}.detailjson`,
video: item.data.moVideoPath,
cover: item.data.mCoverImg,
}));

const items = await Promise.all(
list.map((item) =>
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.title = content('h1.articleHead').text();
item.pubDate = timezone(parseDate(content('span#pubtime_baidu').text()), +8);
item.author = content('span#source_baidu').text();
item.description = content('div.articleText').html();
if (item.video) {
item.description = art(path.join(__dirname, 'templates/description.art'), {
video: item.video,
cover: item.cover,
});
} else {
const detailResponse = await got({
method: 'get',
url: item.link,
});

const data = detailResponse.data;

item.link = `${rootUrl}/#/detailsPage/${id}/${data.id}/1/${data.publishTime.split(' ')[0]}`;
item.description = data.txt;
}

return item;
})
)
);

ctx.state.data = {
title: `${nodes[category].title} 参考消息`,
title: `参考消息 - ${channelResponse.data.name}`,
link: currentUrl,
description: '参考消息',
language: 'zh-cn',
Expand Down
3 changes: 2 additions & 1 deletion lib/v2/cankaoxiaoxi/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/news/:category': ['yuxinliu-alex'],
'/column/:id?': ['yuxinliu-alex', 'nczitzk'],
'/:id?': ['yuxinliu-alex', 'nczitzk'],
};
59 changes: 7 additions & 52 deletions lib/v2/cankaoxiaoxi/radar.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
module.exports = {
'cankaoxiaoxi.com': {
_name: '参考消息',
china: [
'.': [
{
title: '中国新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
title: '栏目',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi-lan-mu',
source: ['/'],
target: '/cankaoxiaoxi/news/china_news',
},
],
culture: [
{
title: '文化新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
source: ['/'],
target: '/cankaoxiaoxi/news/culture_news',
},
],
finance: [
{
title: '财经新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
source: ['/'],
target: '/cankaoxiaoxi/news/finance_news',
},
],
mil: [
{
title: '军事新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
source: ['/'],
target: '/cankaoxiaoxi/news/military_news',
},
],
science: [
{
title: '科技新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
source: ['/'],
target: '/cankaoxiaoxi/news/technology_news',
},
],
tw: [
{
title: '台海新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
source: ['/'],
target: '/cankaoxiaoxi/news/taiwan_news',
},
],
world: [
{
title: '国际新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#can-kao-xiao-xi',
source: ['/'],
target: '/cankaoxiaoxi/news/world_news',
target: (params, url) => {
const urlStr = new URL(url).toString();
return `/cankaoxiaoxi/column${/\/#\//.test(urlStr) ? `/${urlStr.split('/').pop()}` : ''}`;
},
},
],
},
Expand Down
3 changes: 2 additions & 1 deletion lib/v2/cankaoxiaoxi/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/news/:category', require('./index'));
router.get('/column/:id?', require('./'));
router.get('/:id?', require('./'));
};
5 changes: 5 additions & 0 deletions lib/v2/cankaoxiaoxi/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ if video }}
<video controls poster="{{ cover }}">
<source src="{{ video }}" type="video/mp4">
</video>
{{ /if }}
55 changes: 55 additions & 0 deletions lib/v2/modelscope/community.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const path = require('path');
const timezone = require('@/utils/timezone');
const { art } = require('@/utils/render');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const baseUrl = 'https://community.modelscope.cn';

const { data } = await got.post(`${baseUrl}/v1/namespace_page/article`, {
json: { id: 142373, notInMediaAidList: [], pageNum: 1, pageSize: ctx.query.limit ? parseInt(ctx.query.limit) : 30 },
});

const articles = data.data.content.map((c) => ({
title: c.content.name,
description: c.content.desc,
author: c.nickname,
link: `${baseUrl}/${c.content.id}.html`,
pubDate: timezone(parseDate(c.content.createdTime), 8),
category: c.content.externalData.tags.map((t) => t.name),
thumb: c.content.thumb,
}));

const items = await Promise.all(
articles.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(item.link);

const $ = cheerio.load(data);
const initialData = JSON.parse(
$('script')
.text()
.match(/window\.__INITIAL_STATE__\s*=\s*({.*?});/)[1]
);

item.description = art(path.join(__dirname, 'templates/community.art'), {
thumb: item.thumb,
quote: item.description,
content: initialData.pageData.detail.ext.content,
});

return item;
})
)
);

ctx.state.data = {
title: 'ModelScope魔搭社区-DevPress官方社区',
description: 'ModelScope魔搭社区 DevPress官方社区-ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单。',
image: 'https://g.alicdn.com/sail-web/maas/0.8.10/favicon/128.ico',
link: baseUrl,
item: items,
};
};
55 changes: 55 additions & 0 deletions lib/v2/modelscope/datasets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const got = require('@/utils/got');
const md = require('markdown-it')({
html: true,
linkify: true,
});
const path = require('path');
const { art } = require('@/utils/render');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const baseUrl = 'https://modelscope.cn';
const link = `${baseUrl}/datasets`;

const { data } = await got(`${baseUrl}/api/v1/dolphin/datasets`, {
searchParams: {
PageSize: ctx.query.limit ? parseInt(ctx.query.limit) : 36,
PageNumber: 1,
Target: '',
Sort: 'gmt_modified',
},
});

const datasets = data.Data.map((dataset) => ({
title: dataset.ChineseName,
description: dataset.Description,
author: dataset.CreatedBy,
link: `${link}/${dataset.Namespace}/${dataset.Name}`,
pubDate: parseDate(dataset.GmtCreate, 'X'),
category: dataset.UserDefineTags.split(','),
slug: `/${dataset.Namespace}/${dataset.Name}`,
}));

const items = await Promise.all(
datasets.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(`${baseUrl}/api/v1/datasets${item.slug}`);

const content = data.Data.ReadmeContent.replace(/img src="(?!http)(.*?)"/g, `img src="${baseUrl}/api/v1/datasets${item.slug}/repo?Revision=master&FilePath=$1&View=true"`);
item.description = art(path.join(__dirname, 'templates/desc.art'), {
description: item.description,
md: md.render(content),
});
return item;
})
)
);

ctx.state.data = {
title: '数据集首页 · 魔搭社区',
description: 'ModelScope——汇聚各领域先进的机器学习模型,提供模型探索体验、推理、训练、部署和应用的一站式服务。在这里,共建模型开源社区,发现、学习、定制和分享心仪的模型。',
image: 'https://g.alicdn.com/sail-web/maas/0.8.10/favicon/128.ico',
link,
item: items,
};
};
6 changes: 6 additions & 0 deletions lib/v2/modelscope/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'/community': ['TonyRL'],
'/datasets': ['TonyRL'],
'/models': ['TonyRL'],
'/studios': ['TonyRL'],
};
Loading

1 comment on commit 4b42edf

@vercel
Copy link

@vercel vercel bot commented on 4b42edf Mar 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.