diff --git a/lib/routes/dlnews/category.ts b/lib/routes/dlnews/category.ts index fa703c05ef1a78..20f53130322894 100644 --- a/lib/routes/dlnews/category.ts +++ b/lib/routes/dlnews/category.ts @@ -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) { diff --git a/lib/routes/finology/bullets.ts b/lib/routes/finology/bullets.ts index e1c12fb2e8ab5b..5d680005d4e738 100644 --- a/lib/routes/finology/bullets.ts +++ b/lib/routes/finology/bullets.ts @@ -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; } diff --git a/lib/routes/finology/category.ts b/lib/routes/finology/category.ts index 5c34070fa9bab7..b6f5b622bd783b 100644 --- a/lib/routes/finology/category.ts +++ b/lib/routes/finology/category.ts @@ -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); -} - -export async function commonHandler(baseUrl: string, route: string, number: number) { const extra = { + description: (topic: string) => `Articles for your research and knowledge under ${topic}`, 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`, + selector: `div.card`, }; - const listItems = await getItems(`${baseUrl}${route}`, extra); + return await commonHandler('https://insider.finology.in', `/${category}`, extra); +} + +export async function commonHandler(baseUrl: string, route: string, extra: any): Promise { + 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', }; } diff --git a/lib/routes/finology/most-viewed.ts b/lib/routes/finology/most-viewed.ts index b0d233af6c588c..c66f079fe74c94 100644 --- a/lib/routes/finology/most-viewed.ts +++ b/lib/routes/finology/most-viewed.ts @@ -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); } diff --git a/lib/routes/finology/tag.ts b/lib/routes/finology/tag.ts index 68de86769d7996..49c23aad881680 100644 --- a/lib/routes/finology/tag.ts +++ b/lib/routes/finology/tag.ts @@ -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); } diff --git a/lib/routes/finology/utils.ts b/lib/routes/finology/utils.ts index 546d14773b994d..d2e64a3d800ea4 100644 --- a/lib/routes/finology/utils.ts +++ b/lib/routes/finology/utils.ts @@ -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. Check with Website if the page is slow` })); - 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 };