Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add orcid #7582

Merged
merged 25 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5431f17
完成issues#7485,在每日一图-国家地理中增加每日精选节点
OrangeEd1t May 6, 2021
c3ce5e7
修改文档和router位置
OrangeEd1t May 6, 2021
9fa439c
Merge remote-tracking branch 'upstream/master'
OrangeEd1t May 12, 2021
3255f63
对日期pubDate规范进行了调整
OrangeEd1t May 12, 2021
dadbb6f
Merge branch 'issues-#7485'
OrangeEd1t May 12, 2021
7fd967b
优化调整获取内容逻辑,修改pubDate字段的获取方式
OrangeEd1t May 13, 2021
703ccaa
调整pubDate参数
OrangeEd1t May 15, 2021
556db62
删除代码中多余的console
OrangeEd1t May 17, 2021
20bf6ff
调整parse-date引用
OrangeEd1t May 17, 2021
17934e2
Merge remote-tracking branch 'upstream/master'
OrangeEd1t May 19, 2021
279003f
Merge branch 'master' into issues-#7485
OrangeEd1t May 19, 2021
e378a4b
调整时区
OrangeEd1t May 19, 2021
c38f2db
修改国家地理每日一图
OrangeEd1t May 19, 2021
09cd835
issues-#7471,解决国家地理每日一图获取失败问题,因为网站更改,并且网站对图片进行了处理,所以调整获取方式。
OrangeEd1t May 20, 2021
1db9ab4
删除无用代码
OrangeEd1t May 20, 2021
4fdd89d
调整代码,错删了代码
OrangeEd1t May 20, 2021
288c203
重新提交,之前提交后部署失败。
OrangeEd1t May 20, 2021
15df7a1
Merge branch 'feature-geoDailyPhoto'
OrangeEd1t May 20, 2021
fd005b8
Merge branch 'issues-#7485'
OrangeEd1t May 20, 2021
ec5048e
feat:add orcid works route
OrangeEd1t May 25, 2021
864e9c9
feat(route):add ORCID 获取Works(前20条)
OrangeEd1t May 26, 2021
a77e52f
调整代码,使其更加规范
OrangeEd1t May 26, 2021
f43d39b
Merge branch 'upstream' into pr/OrangeEd1t/7582
TonyRL Feb 20, 2022
fcd0e07
fix: remove all unnecessary changes
TonyRL Feb 20, 2022
055480b
refactor: migrate to v2
TonyRL Feb 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,6 @@ type 为 all 时,category 参数不支持 cost 和 free
### はてな匿名ダイアリー - 人気記事アーカイブ

<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>

## ORCID
<Route author="OrangeEd1t" example="orcid/0000-0002-4731-9700" path="/orcid/:id" :paramsDesc="['学术识别号']"/>
6 changes: 5 additions & 1 deletion docs/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,13 @@ R18 显示

## 国家地理

### 每日精选

<Route author="OrangeEd1t" example="/natgeo/dailyselection" path="/natgeo/dailyselection"/>

### 每日一图

<Route author="LogicJake" example="/natgeo/dailyphoto" path="/natgeo/dailyphoto"/>
<Route author="LogicJake & OrangeEd1t" example="/natgeo/dailyphoto" path="/natgeo/dailyphoto"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary changes


## 煎蛋

Expand Down
4 changes: 4 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ router.get('/sexinsex/:id/:type?', require('./routes/sexinsex/index'));
router.get('/gcores/category/:category', require('./routes/gcores/category'));

// 国家地理
router.get('/natgeo/dailyselection', require('./routes/natgeo/dailyselection'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary changes

router.get('/natgeo/dailyphoto', require('./routes/natgeo/dailyphoto'));
router.get('/natgeo/:cat/:type?', require('./routes/natgeo/natgeo'));

Expand Down Expand Up @@ -4085,4 +4086,7 @@ router.get('/hugo/releases', require('./routes/hugo/releases'));
// OR
router.get('/or/:id?', require('./routes/or'));

// ORCID
router.get('/orcid/:id?', require('./routes/orcid'));

module.exports = router;
44 changes: 26 additions & 18 deletions lib/routes/natgeo/dailyphoto.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1;
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
const link = 'https://www.nationalgeographic.com/photo-of-the-day/media-spotlight/';
await page.goto(link);
const html = await page.evaluate(
() =>
document.querySelector('div.InlineGallery').innerHTML
);
browser.close();

const api = `https://www.nationalgeographic.com/content/photography/en_US/photo-of-the-day/_jcr_content/.gallery.${year}-${month}.json`;
const response = await got.get(api);
const items = response.data.items;
const $ = cheerio.load(html);

const out = items.slice(0, 10).map((item) => {
const info = {
title: item.image.title,
author: item.image.credit && item.image.credit.replace('Photograph by ', ''),
link: item.pageUrl,
description: `<img src="${item.image.uri}">` + item.image.caption,
};
return info;
});
const imgUrl = $('img').attr('src');
const title = $('p.Caption__Title').text();
const description = $('span.RichText').text();
const author = $('span.Caption__Credit').text();

const out = new Array;

const info = {
title: title,
link: link,
description: `<img src="${imgUrl}"><br>` + 'Photography by: ' + author + '<br>' + description,
};
out.push(info);

ctx.state.data = {
title: 'Photo of the Day',
link: 'https://www.nationalgeographic.com/photography/photo-of-the-day/',
title: 'Photo Of The Day',
link: link,
item: out,
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary changes

43 changes: 43 additions & 0 deletions lib/routes/natgeo/dailyselection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const {
parseDate
} = require('@/utils/parse-date');

module.exports = async (ctx) => {
const host = 'http://dili.bdatu.com/jiekou/mains/p1.html';
const data = await got.get(host);

let sort = 0;
let addtime = '';

for (let i = 0; i < data.data.album.length; i++) {
if (parseInt(data.data.album[i].ds) === 1) {
sort = data.data.album[i].sort;
addtime = data.data.album[i].addtime;
break;
}
}
const api = 'http://dili.bdatu.com/jiekou/albums/a' + sort + '.html';
const response = await got.get(api);
const items = response.data.picture;
const out = new Array;

items.map((item) => {
const info = {
title: item.title,
link: item.url,
description: `<img src="${item.url}"><br>` + item.content,
pubDate: timezone(parseDate(addtime), +0),
guid: item.id,
};
out.push(info);
return info;
});

ctx.state.data = {
title: 'Photo of the Daily Selection',
link: api,
item: out,
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary changes

45 changes: 45 additions & 0 deletions lib/routes/orcid/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const got = require('@/utils/got');

module.exports = async (ctx) => {
const id = ctx.params.id || '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const id = ctx.params.id || '';
const id = ctx.params.id ?? '';

const rootUrl = 'https://orcid.org/';
const currentUrl = `${rootUrl}${id ? `${id}/worksPage.json?offset=0&sort=date&sortAsc=false&pageSize=20` : ''}`;
const response = await got.get(currentUrl);

const items = response.data.groups;
const works = new Array;
const out = new Array;

for (let i = 0; i < items.length; i++) {
for (let j = 0; j < items[i].works.length; j++) {
works.push(items[i].works[j]);
}
}

works.map((work) => {
let Str = '';

for (let l = 0; l < work.workExternalIdentifiers.length; l++) {
if (work.workExternalIdentifiers[l].url) {
Str = Str + work.workExternalIdentifiers[l].externalIdentifierType.value + ': ' + work.workExternalIdentifiers[l].externalIdentifierId.value + '(URL: ' + work.workExternalIdentifiers[l].url.value + ')<br>';
} else {
Str = Str + work.workExternalIdentifiers[l].externalIdentifierType.value + ': ' + work.workExternalIdentifiers[l].externalIdentifierId.value + '<br>';
}
}

const info = {
title: work.title.value,
link: work.url,
description: `<h2>${work.title.value}</h2><h3>${work.journalTitle.value}</h3><span>${work.publicationDate.year ? `${work.publicationDate.year}-` : ``}${work.publicationDate.month}${work.publicationDate.day ? `-${work.publicationDate.day}` : ``} | ${work.workType.value}</span><br><span>${Str}</span><span>Source: ${work.sourceName}`,
Copy link
Collaborator

@TonyRL TonyRL Feb 1, 2022

Choose a reason for hiding this comment

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

Please use art-template to create HTML #8359

guid: work.putCode.value,
};
out.push(info);
return info;
});

ctx.state.data = {
title: 'ORCID Works List',
link: currentUrl,
item: out,
};
};
40 changes: 22 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"parse-torrent": "9.1.3",
"pidusage": "2.0.21",
"plist": "3.0.2",
"puppeteer": "9.1.1",
"puppeteer": "^9.1.1",
"query-string": "7.0.0",
"require-all": "3.0.0",
"rss-parser": "3.10.0",
Expand Down