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

Feature geo daily photo #7554

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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"/>

## 煎蛋

Expand Down
1 change: 1 addition & 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'));
router.get('/natgeo/dailyphoto', require('./routes/natgeo/dailyphoto'));
router.get('/natgeo/:cat/:type?', require('./routes/natgeo/natgeo'));

Expand Down
43 changes: 26 additions & 17 deletions lib/routes/natgeo/dailyphoto.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
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,
};
};
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,
};
};