Skip to content

Commit

Permalink
feat(route): Add 国家哲学社会科学文献中心 (#14737)
Browse files Browse the repository at this point in the history
* feat(route) Add 国家哲学社会科学文献中心

* Adapt to new namespace

* Update lib/routes/ncpssd/newlist.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/ncpssd/newlist.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/ncpssd/newlist.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/ncpssd/newlist.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/ncpssd/newlist.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix: cr

---------
  • Loading branch information
LyleLee authored Apr 5, 2024
1 parent 9a41023 commit c454200
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/ncpssd/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '国家哲学社会科学文献中心',
url: 'ncpssd.cn',
};
98 changes: 98 additions & 0 deletions lib/routes/ncpssd/newlist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { Route } from '@/types';

export const route: Route = {
path: '/newlist',
categories: ['study'],
example: '/ncpssd/newlist',
radar: [
{
source: ['ncpssd.cn/', 'ncpssd.cn/newlist'],
},
],
name: '最新文献',
maintainers: ['LyleLee'],
handler,
url: 'ncpssd.cn/',
};

async function handler() {
const baseUrl = 'https://www.ncpssd.cn';
const argument = '/newlist?type=0';

const response = await got({
method: 'get',
url: baseUrl + argument,
});

const data = response.data;
const $ = load(data);
const items = $('.news-list > li');

const list = items.toArray().map((p) => {
const title = $(p)
.find('a')
.text()
.replaceAll(/(\r\n|\n|\r)/gm, '')
.trim();
const articleUrl =
baseUrl +
$(p)
.find('a')
.attr('onclick')
?.match(/\('(.*?)'\)/)?.[1];
const parseUrl = new URL(articleUrl);

return {
title,
link: articleUrl,
lngid: parseUrl.searchParams.get('id'),
type: parseUrl.searchParams.get('typename'),
pageType: parseUrl.searchParams.get('nav'),
};
});

const paper = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const url = 'https://www.ncpssd.cn/articleinfoHandler/getjournalarticletable'; // Adjust the URL accordingly
const headers = {
Accept: 'application/json, text/javascript, */*; q=0.01',
'Content-Type': 'application/json; charset=UTF-8',
};

const requestBody = {
lngid: item.lngid,
type: item.type,
pageType: item.pageType,
};

const response = await got.post(url, {
headers,
json: requestBody,
responseType: 'json', // Set the expected response type
});

return {
title: item.title,
link: item.link,
author: response.data.data.showwriter,
description: response.data.data.remarkc,
pubDate: parseDate(response.data.data.publishDateTime),
};
})
)
);

return {
// 源标题
title: '国家哲学社会科学文献中心',
// 源链接
link: baseUrl + argument,
// 源文章
item: paper,
};
}

0 comments on commit c454200

Please sign in to comment.