From 549993931e426083cbb5cda45299c9e682d2a72e Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 22 May 2024 03:48:02 +0800 Subject: [PATCH] fix(route): finology (#15652) --- lib/routes/finology/bullets.ts | 9 --- lib/routes/finology/category.ts | 60 +++++++++++++++++ lib/routes/finology/most-viewed.ts | 16 ++--- lib/routes/finology/tag.ts | 105 ++++++++++++----------------- lib/routes/finology/utils.ts | 5 +- 5 files changed, 109 insertions(+), 86 deletions(-) create mode 100644 lib/routes/finology/category.ts diff --git a/lib/routes/finology/bullets.ts b/lib/routes/finology/bullets.ts index 3616aca5b..e1c12fb2e 100644 --- a/lib/routes/finology/bullets.ts +++ b/lib/routes/finology/bullets.ts @@ -7,15 +7,6 @@ export const route: Route = { path: '/bullets', categories: ['finance'], example: '/finology/bullets', - parameters: {}, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, radar: [ { source: ['insider.finology.in/bullets'], diff --git a/lib/routes/finology/category.ts b/lib/routes/finology/category.ts new file mode 100644 index 000000000..67dc9646f --- /dev/null +++ b/lib/routes/finology/category.ts @@ -0,0 +1,60 @@ +import { Route } from '@/types'; +import { getItems } from './utils'; +import type { Context } from 'hono'; + +export const route: Route = { + path: '/:category', + categories: ['finance'], + example: '/finology/success-stories', + parameters: { category: 'Refer Table below or find in URL' }, + radar: [ + { + source: ['insider.finology.in/:category'], + }, + ], + name: 'Category', + maintainers: ['Rjnishant530'], + handler, + description: `:::note Category + | Category | Link | + | --------------------- | ------------------ | + | **Business** | business | + | Big Shots | entrepreneurship | + | Startups | startups-india | + | Brand Games | success-stories | + | Juicy Scams | juicy-scams | + | **Finance** | finance | + | Macro Moves | economy | + | News Platter | market-news | + | Tax Club | tax | + | Your Money | your-money | + | **Invest** | investing | + | Stock Market | stock-market | + | Financial Ratios | stock-ratios | + | Investor's Psychology | behavioral-finance | + | Mutual Funds | mutual-fund | + :::`, +}; + +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 = { + 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); + return { + title: `${extra.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', + language: 'en-us', + }; +} diff --git a/lib/routes/finology/most-viewed.ts b/lib/routes/finology/most-viewed.ts index 0d854bdc5..b0d233af6 100644 --- a/lib/routes/finology/most-viewed.ts +++ b/lib/routes/finology/most-viewed.ts @@ -6,19 +6,11 @@ export const route: Route = { path: '/most-viewed/:time', categories: ['finance'], example: '/finology/most-viewed/monthly', - parameters: { time: 'N' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, + parameters: { time: '`alltime` or `monthly` only' }, radar: [ { - source: ['insider.finology.in/:category'], - target: '/:category', + source: ['insider.finology.in/most-viewed'], + target: '/most-viewed/monthly', }, ], name: 'Most Viewed', @@ -45,7 +37,7 @@ async function handler(ctx) { date: false, selector, }; - const listItems = await getItems(ctx, baseUrl, extra); + const listItems = await getItems(baseUrl, extra); return { title: `Most Viewed ${title} - Finology Insider`, link: baseUrl, diff --git a/lib/routes/finology/tag.ts b/lib/routes/finology/tag.ts index 688c0d4ac..c5a66f35d 100644 --- a/lib/routes/finology/tag.ts +++ b/lib/routes/finology/tag.ts @@ -1,76 +1,55 @@ import { Route } from '@/types'; -import logger from '@/utils/logger'; -import { getItems } from './utils'; +import { commonHandler } from './category'; +import type { Context } from 'hono'; export const route: Route = { - path: ['/:category', '/tag/:topic'], + path: '/tag/:topic', categories: ['finance'], - example: '/finology/success-stories', - parameters: { category: 'N' }, - features: { - requireConfig: false, - requirePuppeteer: false, - antiCrawler: false, - supportBT: false, - supportPodcast: false, - supportScihub: false, - }, + example: '/finology/tag/startups', + parameters: { category: 'Refer Table below or find in URL' }, radar: [ { - source: ['insider.finology.in/:category'], + source: ['insider.finology.in/tag/:topic'], }, ], - name: 'Category', + name: 'Trending Topic', maintainers: ['Rjnishant530'], handler, - description: `:::note Category - | Category | Link | - | --------------------- | ------------------ | - | **Business** | business | - | Big Shots | entrepreneurship | - | Startups | startups-india | - | Brand Games | success-stories | - | Juicy Scams | juicy-scams | - | **Finance** | finance | - | Macro Moves | economy | - | News Platter | market-news | - | Tax Club | tax | - | Your Money | your-money | - | **Invest** | investing | - | Stock Market | stock-market | - | Financial Ratios | stock-ratios | - | Investor's Psychology | behavioral-finance | - | Mutual Funds | mutual-fund | - :::`, + description: `:::note Topic + | Topic | Link | + | ------------------------ | ------------------------ | + | Investment Decisions | investment-decisions | + | Investing 101 | investing-101 | + | Stock Markets | stock-markets | + | business news india | business-news-india | + | Company Analysis | company-analysis | + | Business and brand tales | business-and-brand-tales | + | Featured | featured | + | Fundamental Analysis | fundamental-analysis | + | Business Story | business-story | + | All Biz | all-biz | + | Stock Analysis | stock-analysis | + | Automobile Industry | automobile-industry | + | Indian Economy | indian-economy | + | Govt's Words | govt%27s-words | + | Behavioral Finance | behavioral-finance | + | Global Economy | global-economy | + | Startups | startups | + | GST | gst | + | Product Review | product-review | + | My Pocket | my-pocket | + | Business Games | business-games | + | Business Models | business-models | + | Indian Indices | indian-indices | + | Banking System | banking-system | + | Debt | debt | + | World News | world-news | + | Technology | technology | + | Regulatory Bodies | regulatory-bodies | +:::`, }; -async function handler(ctx) { - const { topic, category } = ctx.req.param(); - const baseUrl = 'https://insider.finology.in'; - let route; - let number; - if (topic) { - route = `/tag/${topic}`; - number = 2; - } else if (category) { - route = `/${category}`; - number = 6; - } else { - logger.error('Invalid URL'); - } - 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(ctx, `${baseUrl}${route}`, extra); - return { - title: `${extra.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', - language: 'en-us', - }; +async function handler(ctx: Context) { + const { topic } = ctx.req.param(); + return await commonHandler('https://insider.finology.in', `/tag/${topic}`, 2); } diff --git a/lib/routes/finology/utils.ts b/lib/routes/finology/utils.ts index 28e3b563f..546d14773 100644 --- a/lib/routes/finology/utils.ts +++ b/lib/routes/finology/utils.ts @@ -2,8 +2,9 @@ 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'; -const getItems = async (ctx, url, extra) => { +const getItems = async (url: string, extra: { date: boolean; selector: string; topicName?: string }) => { const mainUrl = 'https://insider.finology.in'; const { data: response } = await got(url); const $ = load(response); @@ -13,7 +14,7 @@ const getItems = async (ctx, url, extra) => { item = $(item); const title = item.find('p.text-m-height').text(); const link = item.find('a').attr('href'); - const pubDate = extra.date ? parseDate(item.find('div.text-light p').first().text(), 'DD-MMM-YYYY') : ''; + 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 {