Skip to content

Commit

Permalink
Merge pull request #18 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 Dec 13, 2023
2 parents 0b2e8f8 + 3f7c8d9 commit 0a20fac
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 230 deletions.
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ router.get('/netflix/newsroom/:category?/:region?', lazyloadRouteHandler('./rout
router.get('/sbs/chinese/:category?/:id?/:dialect?/:language?', lazyloadRouteHandler('./routes/sbs/chinese'));

// QuestMobile
router.get('/questmobile/report/:category?/:label?', lazyloadRouteHandler('./routes/questmobile/report'));
// router.get('/questmobile/report/:category?/:label?', lazyloadRouteHandler('./routes/questmobile/report'));

// Fashion Network
router.get('/fashionnetwork/news/:sectors?/:categories?/:language?', lazyloadRouteHandler('./routes/fashionnetwork/news.js'));
Expand Down
121 changes: 0 additions & 121 deletions lib/routes/questmobile/report.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/v2/picnob/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
'/user/:id': ['TonyRL'],
'/user/:id': ['TonyRL', 'micheal-death'],
};
6 changes: 3 additions & 3 deletions lib/v2/picnob/templates/desc.art
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<source src="{{ item.video }}" type="video/mp4">
</video>
{{ else if item.type === 'img_multi' }}
{{ each images i }}
<a href="{{ i.ori }}"><img src="{{ i.url }}"></a>
{{ each item.images i }}
<img src="{{ i.url }}">
{{ /each }}
{{ else if item.type === 'img_sig' }}
<a href="{{ item.pic }}"><img src="{{ item.pic }}"></a>
<img src="{{ item.pic }}">
{{ /if }}
<br>
{{@ item.sum }}
111 changes: 74 additions & 37 deletions lib/v2/picnob/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,90 @@ const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const { puppeteerGet } = require('./utils');

module.exports = async (ctx) => {
const baseUrl = 'https://www.picnob.com';
const { id } = ctx.params;
const url = `${baseUrl}/profile/${id}/`;
const { data: response } = await got(url);
const $ = cheerio.load(response);

const browser = await require('@/utils/puppeteer')();
// TODO: can't bypass cloudflare 403 error without puppeteer
let html;
let usePuppeteer = false;
try {
const { data } = await got(url, {
headers: {
accept: 'text/html',
referer: 'https://www.google.com/',
},
});
html = data;
} catch (e) {
if (e.message.includes('code 403')) {
html = await puppeteerGet(url, browser);
usePuppeteer = true;
}
}
const $ = cheerio.load(html);
const profileName = $('h1.fullname').text();
const userId = $('input[name=userid]').attr('value');

const { data } = await got(`${baseUrl}/api/posts`, {
searchParams: {
userid: userId,
},
});
let posts;
if (!usePuppeteer) {
const { data } = await got(`${baseUrl}/api/posts`, {
headers: {
accept: 'application/json',
},
searchParams: {
userid: userId,
},
});
posts = data.posts;
} else {
const data = await puppeteerGet(`${baseUrl}/api/posts?userid=${userId}`, browser);
posts = data.posts;
}

const list = data.posts.items.map(async (item) => {
const { shortcode, type } = item;
const link = `${baseUrl}/post/${shortcode}/`;
let images = [];
if (type === 'img_multi') {
images = await ctx.cache.tryGet(link, async () => {
const { data } = await got(link);
const $ = cheerio.load(data);
return [
...new Set(
$('.post_slide a')
.toArray()
.map((a) => {
a = $(a);
return {
ori: a.attr('href'),
url: a.find('img').attr('data-src'),
};
})
),
];
});
}
return {
title: item.sum_pure,
description: art(path.join(__dirname, 'templates/desc.art'), { item, images }),
link,
pubDate: parseDate(item.time, 'X'),
};
});
const list = await Promise.all(
posts.items.map(async (item) => {
const { shortcode, type } = item;
const link = `${baseUrl}/post/${shortcode}/`;
if (type === 'img_multi') {
item.images = await ctx.cache.tryGet(link, async () => {
let html;
if (!usePuppeteer) {
const { data } = await got(link);
html = data;
} else {
html = await puppeteerGet(link, browser);
}
const $ = cheerio.load(html);
return [
...new Set(
$('.post_slide a')
.toArray()
.map((a) => {
a = $(a);
return {
ori: a.attr('href'),
url: a.find('img').attr('data-src'),
};
})
),
];
});
}

return {
title: item.sum_pure,
description: art(path.join(__dirname, 'templates/desc.art'), { item }),
link,
pubDate: parseDate(item.time, 'X'),
};
})
);
await browser.close();

ctx.state.data = {
title: `${profileName} (@${id}) - Picnob`,
Expand Down
24 changes: 24 additions & 0 deletions lib/v2/picnob/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const puppeteerGet = async (url, browser) => {
let data;
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (request) => {
request.resourceType() === 'document' ? request.continue() : request.abort();
});
page.on('response', async (response) => {
if (response.request().url().includes('/api/posts')) {
data = await response.json();
} else {
data = await response.text();
}
});
await page.goto(url, {
waitUntil: 'domcontentloaded',
});
await page.close();
return data;
};

module.exports = {
puppeteerGet,
};
3 changes: 3 additions & 0 deletions lib/v2/questmobile/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/report/:industry?/:label?': ['nczitzk'],
};
18 changes: 18 additions & 0 deletions lib/v2/questmobile/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
'questmobile.com.cn': {
_name: 'QuestMobile',
'.': [
{
title: '行业研究报告',
docs: 'https://docs.rsshub.app/routes/new-media#questmobile-hang-ye-yan-jiu-bao-gao',
source: ['/research/reports/:industry/:label'],
target: (params) => {
const industry = params.industry;
const label = params.label;

return `/questmobile/report/${industry}/${label}`;
},
},
],
},
};
Loading

0 comments on commit 0a20fac

Please sign in to comment.