forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Finology): fixed Finology routes to new standards (DIYgod#18023)
* fix: finology * use ofetch from '@/utils/ofetch'; * comments changes * Discard changes to lib/types.ts --------- Co-authored-by: rjnishant530 <[email protected]>
- Loading branch information
1 parent
2c3a16f
commit a1d8565
Showing
6 changed files
with
95 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |