fix(Finology): fixed Finology routes to new standards (#18023)
* fix: finology * use ofetch from '@/utils/ofetch'; * comments changes * Discard changes to lib/types.ts --------- Co-authored-by: rjnishant530 <singhnisant530@gmail.com>
This commit is contained in:
parent
2c3a16f9c5
commit
a1d85656fb
|
|
@ -69,10 +69,11 @@ export const route: Route = {
|
|||
target: '/:category',
|
||||
},
|
||||
],
|
||||
name: 'Unknown',
|
||||
url: 'dlnews.com/articles',
|
||||
name: 'Latest News',
|
||||
maintainers: ['Rjnishant530'],
|
||||
handler,
|
||||
url: 'dlnews.com/articles/',
|
||||
example: '/dlnews/people-culture',
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,22 @@
|
|||
import { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { Data, Route, ViewType } from '@/types';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/bullets',
|
||||
categories: ['finance'],
|
||||
view: ViewType.Notifications,
|
||||
example: '/finology/bullets',
|
||||
parameters: {},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['insider.finology.in/bullets'],
|
||||
|
|
@ -21,20 +31,20 @@ export const route: Route = {
|
|||
async function handler() {
|
||||
const baseUrl = 'https://insider.finology.in/bullets';
|
||||
|
||||
const { data: response } = await got(baseUrl);
|
||||
const response = await ofetch(baseUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const listItems = $('ul.timeline li.m-pb2')
|
||||
const listItems = $('body > div.flex.bullettext > div.w80 > div')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const time = item.find('div.timeline-info span').text().split(', ')[1];
|
||||
const a = item.find('a.bullet_share_div');
|
||||
const description = item.find('div.bullet-desc').html();
|
||||
const $item = $(item);
|
||||
const time = $item.find('div.timeline-info span').text().split(', ')[1];
|
||||
const a = $item.find('a.timeline-title');
|
||||
const description = $item.find('div.bullet-desc').html();
|
||||
return {
|
||||
title: a.attr('data-bullettitle'),
|
||||
link: a.attr('data-bulleturl'),
|
||||
pubDate: parseDate(time, 'DD MMMM'),
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
pubDate: parseDate(time),
|
||||
description,
|
||||
};
|
||||
});
|
||||
|
|
@ -44,8 +54,8 @@ async function handler() {
|
|||
link: baseUrl,
|
||||
item: listItems,
|
||||
description: 'Your daily dose of crisp, spicy financial news in 80 words.',
|
||||
logo: 'https://assets.finology.in/insider/images/favicon/apple-touch-icon.png',
|
||||
icon: 'https://assets.finology.in/insider/images/favicon/favicon-32x32.png',
|
||||
logo: 'https://insider.finology.in/Images/favicon/favicon.ico',
|
||||
icon: 'https://insider.finology.in/Images/favicon/favicon.ico',
|
||||
language: 'en-us',
|
||||
};
|
||||
} as Data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { Route } from '@/types';
|
||||
import { Data, Route } from '@/types';
|
||||
import { getItems } from './utils';
|
||||
import type { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/:category',
|
||||
path: '/category/:category',
|
||||
categories: ['finance'],
|
||||
url: 'insider.finology.in/business',
|
||||
example: '/finology/success-stories',
|
||||
parameters: { category: 'Refer Table below or find in URL' },
|
||||
radar: [
|
||||
|
|
@ -38,23 +39,23 @@ export const route: Route = {
|
|||
|
||||
async function handler(ctx: Context) {
|
||||
const { category } = ctx.req.param();
|
||||
return await commonHandler('https://insider.finology.in', `/${category}`, 6);
|
||||
const extra = {
|
||||
description: (topic: string) => `Articles for your research and knowledge under ${topic}`,
|
||||
date: true,
|
||||
selector: `div.card`,
|
||||
};
|
||||
return await commonHandler('https://insider.finology.in', `/${category}`, extra);
|
||||
}
|
||||
|
||||
export async function commonHandler(baseUrl: string, route: string, number: number) {
|
||||
const extra = {
|
||||
date: true,
|
||||
topicName: '',
|
||||
selector: `div.w100.pb${number}.bg-color.flex.flex-col.align-center div.w23.br0625.shadow.position-r.bg-white.m-w100.card.t-w45`,
|
||||
};
|
||||
const listItems = await getItems(`${baseUrl}${route}`, extra);
|
||||
export async function commonHandler(baseUrl: string, route: string, extra: any): Promise<Data> {
|
||||
const { items, topicName } = await getItems(`${baseUrl}${route}`, extra);
|
||||
return {
|
||||
title: `${extra.topicName} - Finology Insider`,
|
||||
title: `${topicName} - Finology Insider`,
|
||||
link: `${baseUrl}${route}`,
|
||||
item: listItems,
|
||||
description: number === 2 ? `Everything that Insider has to offer about ${extra.topicName} for you to read and learn.` : `Articles for your research and knowledge under ${extra.topicName}`,
|
||||
logo: 'https://assets.finology.in/insider/images/favicon/apple-touch-icon.png',
|
||||
icon: 'https://assets.finology.in/insider/images/favicon/favicon-32x32.png',
|
||||
item: items,
|
||||
description: extra.description(topicName || ''),
|
||||
logo: 'https://insider.finology.in/Images/favicon/favicon.ico',
|
||||
icon: 'https://insider.finology.in/Images/favicon/favicon.ico',
|
||||
language: 'en-us',
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,50 +1,27 @@
|
|||
import { Route } from '@/types';
|
||||
import logger from '@/utils/logger';
|
||||
import { getItems } from './utils';
|
||||
import { commonHandler } from './category';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/most-viewed/:time',
|
||||
path: '/most-viewed',
|
||||
categories: ['finance'],
|
||||
example: '/finology/most-viewed/monthly',
|
||||
parameters: { time: '`alltime` or `monthly` only' },
|
||||
example: '/finology/most-viewed',
|
||||
radar: [
|
||||
{
|
||||
source: ['insider.finology.in/most-viewed'],
|
||||
target: '/most-viewed/monthly',
|
||||
target: '/most-viewed',
|
||||
},
|
||||
],
|
||||
name: 'Most Viewed',
|
||||
maintainers: ['Rjnishant530'],
|
||||
handler,
|
||||
url: 'insider.finology.in/most-viewed',
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const baseUrl = 'https://insider.finology.in/most-viewed';
|
||||
let selector;
|
||||
let title;
|
||||
const time = ctx.req.param('time');
|
||||
if (time === 'alltime') {
|
||||
title = 'All Time';
|
||||
selector = 'div.w100.pb2.bg-color.flex.flex-col.align-center.pt6 div.w23.br0625.shadow.position-r.bg-white.m-w100.card.t-w45';
|
||||
} else if (time === 'monthly') {
|
||||
title = 'Monthly';
|
||||
selector = 'div.w100.pb2.bg-color.flex.flex-col.align-center:not(.pt6) div.w23.br0625.shadow.position-r.bg-white.m-w100.card.t-w45';
|
||||
} else {
|
||||
logger.error('Invalid Time');
|
||||
}
|
||||
|
||||
async function handler() {
|
||||
const extra = {
|
||||
description: (topic: string) => `Check out the most talked-about articles among our readers! ${topic}`,
|
||||
date: false,
|
||||
selector,
|
||||
};
|
||||
const listItems = await getItems(baseUrl, extra);
|
||||
return {
|
||||
title: `Most Viewed ${title} - Finology Insider`,
|
||||
link: baseUrl,
|
||||
item: listItems,
|
||||
description: "A lot of Insider's readers seem to be reading these articles. Take a look and find out why.",
|
||||
logo: 'https://assets.finology.in/insider/images/favicon/apple-touch-icon.png',
|
||||
icon: 'https://assets.finology.in/insider/images/favicon/favicon-32x32.png',
|
||||
language: 'en-us',
|
||||
selector: `div.card`,
|
||||
};
|
||||
return await commonHandler('https://insider.finology.in', '/most-viewed', extra);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ export const route: Route = {
|
|||
name: 'Trending Topic',
|
||||
maintainers: ['Rjnishant530'],
|
||||
handler,
|
||||
description: `::: info Topic
|
||||
url: 'insider.finology.in/tag',
|
||||
description: `:::note Topic
|
||||
| Topic | Link |
|
||||
| ------------------------ | ------------------------ |
|
||||
| Investment Decisions | investment-decisions |
|
||||
|
|
@ -51,5 +52,10 @@ export const route: Route = {
|
|||
|
||||
async function handler(ctx: Context) {
|
||||
const { topic } = ctx.req.param();
|
||||
return await commonHandler('https://insider.finology.in', `/tag/${topic}`, 2);
|
||||
const extra = {
|
||||
description: (topic: string) => `Everything that Insider has to offer about ${topic} for you to read and learn.`,
|
||||
date: true,
|
||||
selector: `div.card`,
|
||||
};
|
||||
return await commonHandler('https://insider.finology.in', `/tag/${topic}`, extra);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +1,65 @@
|
|||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { DataItem } from '@/types';
|
||||
|
||||
const getItems = async (url: string, extra: { date: boolean; selector: string; topicName?: string }) => {
|
||||
const getItems = async (url: string, extra: { date: boolean; selector: string }) => {
|
||||
const mainUrl = 'https://insider.finology.in';
|
||||
const { data: response } = await got(url);
|
||||
const response = await ofetch(url);
|
||||
const $ = load(response);
|
||||
const listItems = $(extra.selector)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const title = item.find('p.text-m-height').text();
|
||||
const link = item.find('a').attr('href');
|
||||
const pubDate = extra.date ? timezone(parseDate(item.find('div.text-light p').first().text()), 0) : '';
|
||||
const itunes_item_image = item.find('img').attr('src');
|
||||
const category = item.find('p.pt025').text();
|
||||
const $item = $(item);
|
||||
const title = $item.find('p.text-m-height').text();
|
||||
const link = $item.find('a').attr('href');
|
||||
const pubDate = extra.date ? timezone(parseDate($item.find('div.text-light p').first().text()), 0) : '';
|
||||
const itunes_item_image = $item.find('img').attr('src');
|
||||
const category = [$item.find('p.pt025').text()];
|
||||
return {
|
||||
title,
|
||||
link: `${mainUrl}${link}`,
|
||||
pubDate,
|
||||
itunes_item_image,
|
||||
category,
|
||||
};
|
||||
} as DataItem;
|
||||
});
|
||||
|
||||
const items = (
|
||||
await Promise.allSettled(
|
||||
listItems.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
listItems.map((item) => {
|
||||
if (item.link === undefined) {
|
||||
return item;
|
||||
}
|
||||
return cache.tryGet(item.link, async () => {
|
||||
const response = await ofetch(item.link || '');
|
||||
const $ = load(response);
|
||||
const div = $('div.w60.flex.flex-wrap-badge');
|
||||
item.author = div.find('div a p').text();
|
||||
item.updated = div.find('p:contains("Updated on") span').text();
|
||||
item.description = $('div#main-wrapper div#insiderhead')
|
||||
.find('div.flex.flex-col.w100.align-center')
|
||||
.children('div.m-position-r')
|
||||
.remove()
|
||||
.end()
|
||||
.find('a[href="https://quest.finology.in/"]')
|
||||
.remove()
|
||||
.end()
|
||||
.find('div.blur-wall-wrap')
|
||||
.remove()
|
||||
.end()
|
||||
.html();
|
||||
item.updated = extra.date ? parseDate(div.find('p:contains("Updated on") span').text()) : '';
|
||||
item.description =
|
||||
$('div#main-wrapper div#insiderhead')
|
||||
.find('div.flex.flex-col.w100.align-center')
|
||||
.children('div.m-position-r')
|
||||
.remove()
|
||||
.end()
|
||||
.find('a[href="https://quest.finology.in/"]')
|
||||
.remove()
|
||||
.end()
|
||||
.find('div.blur-wall-wrap')
|
||||
.remove()
|
||||
.end()
|
||||
.html() ?? '';
|
||||
return item;
|
||||
})
|
||||
)
|
||||
});
|
||||
})
|
||||
)
|
||||
).map((v, index) => (v.status === 'fulfilled' ? v.value : { ...listItems[index], description: `Website did not load within Timeout Limits. <a href="${listItems[index].link}">Check with Website if the page is slow</a>` }));
|
||||
extra.topicName = $('h1.font-heading.fs1875')?.text();
|
||||
|
||||
return items;
|
||||
const topicName = $('h1.font-heading.fs1875')?.text();
|
||||
const validItems: DataItem[] = items.filter((item): item is DataItem => item !== null && typeof item !== 'string');
|
||||
return { items: validItems, topicName };
|
||||
};
|
||||
|
||||
export { getItems };
|
||||
|
|
|
|||
Loading…
Reference in New Issue