From 28d643e5c421a8852c4b8a94d83f5fbcbde16698 Mon Sep 17 00:00:00 2001
From: Nishant Singh <57475999+Rjnishant530@users.noreply.github.com>
Date: Mon, 14 Aug 2023 18:09:17 +0530
Subject: [PATCH] feat(route): add Finology (#12993)
* feat(route): add Finology
* Update radar.js
* Update docs/en/finance.md
* Update lib/v2/finology/bullets.js
* Update lib/v2/finology/mostViewed.js
* Update lib/v2/finology/bullets.js
* Update docs/en/finance.md
* Update lib/v2/finology/tag.js
* Update lib/v2/finology/mostViewed.js
* Update lib/v2/finology/tag.js
* add the suggested changes
* use promise.allSettled
* clean up
* docs: add spoiler
---------
---
docs/en/finance.md | 79 +++++++++++++++++++++++++++++++++++
lib/v2/finology/bullets.js | 35 ++++++++++++++++
lib/v2/finology/maintainer.js | 6 +++
lib/v2/finology/mostViewed.js | 33 +++++++++++++++
lib/v2/finology/radar.js | 31 ++++++++++++++
lib/v2/finology/router.js | 6 +++
lib/v2/finology/tag.js | 33 +++++++++++++++
lib/v2/finology/utils.js | 58 +++++++++++++++++++++++++
8 files changed, 281 insertions(+)
create mode 100644 lib/v2/finology/bullets.js
create mode 100644 lib/v2/finology/maintainer.js
create mode 100644 lib/v2/finology/mostViewed.js
create mode 100644 lib/v2/finology/radar.js
create mode 100644 lib/v2/finology/router.js
create mode 100644 lib/v2/finology/tag.js
create mode 100644 lib/v2/finology/utils.js
diff --git a/docs/en/finance.md b/docs/en/finance.md
index 1df9ce702..9d1129945 100644
--- a/docs/en/finance.md
+++ b/docs/en/finance.md
@@ -37,6 +37,85 @@ pageClass: routes
+## Finology Insider
+
+### Bullets
+
+
+
+### Category
+
+
+
+::: details 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 |
+
+:::
+
+
+
+### Most Viewed
+
+
+
+### Trending Topic
+
+
+
+::: details 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 |
+
+:::
+
+
+
## finviz
### News
diff --git a/lib/v2/finology/bullets.js b/lib/v2/finology/bullets.js
new file mode 100644
index 000000000..6c1349b8e
--- /dev/null
+++ b/lib/v2/finology/bullets.js
@@ -0,0 +1,35 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+
+module.exports = async (ctx) => {
+ const baseUrl = 'https://insider.finology.in/bullets';
+
+ const { data: response } = await got(baseUrl);
+ const $ = cheerio.load(response);
+
+ const listItems = $('ul.timeline li.m-pb2')
+ .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();
+ return {
+ title: a.attr('data-bullettitle'),
+ link: a.attr('data-bulleturl'),
+ pubDate: parseDate(time, 'DD MMMM'),
+ description,
+ };
+ });
+
+ ctx.state.data = {
+ title: 'Finology Insider Bullets',
+ 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',
+ language: 'en-us',
+ };
+};
diff --git a/lib/v2/finology/maintainer.js b/lib/v2/finology/maintainer.js
new file mode 100644
index 000000000..d6191c63e
--- /dev/null
+++ b/lib/v2/finology/maintainer.js
@@ -0,0 +1,6 @@
+module.exports = {
+ '/bullets': ['Rjnishant530'],
+ '/:category': ['Rjnishant530'],
+ '/most-viewed/:time': ['Rjnishant530'],
+ '/tag/:topic': ['Rjnishant530'],
+};
diff --git a/lib/v2/finology/mostViewed.js b/lib/v2/finology/mostViewed.js
new file mode 100644
index 000000000..c59fc8431
--- /dev/null
+++ b/lib/v2/finology/mostViewed.js
@@ -0,0 +1,33 @@
+const logger = require('@/utils/logger');
+const { getItems } = require('./utils');
+
+module.exports = async (ctx) => {
+ const baseUrl = 'https://insider.finology.in/most-viewed';
+ let selector;
+ let title;
+ const { time } = ctx.params;
+ 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');
+ }
+
+ const extra = {
+ date: false,
+ selector,
+ };
+ const listItems = await getItems(ctx, baseUrl, extra);
+ ctx.state.data = {
+ 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',
+ };
+};
diff --git a/lib/v2/finology/radar.js b/lib/v2/finology/radar.js
new file mode 100644
index 000000000..23e2194be
--- /dev/null
+++ b/lib/v2/finology/radar.js
@@ -0,0 +1,31 @@
+module.exports = {
+ 'finology.in': {
+ _name: 'Finology Insider',
+ insider: [
+ {
+ title: 'Bullets',
+ docs: 'https://docs.rsshub.app/en/finance.html#finology-insider',
+ source: ['/bullets'],
+ target: '/finology/bullets',
+ },
+ {
+ title: 'Category',
+ docs: 'https://docs.rsshub.app/en/finance.html#finology-insider',
+ source: '/:category',
+ target: '/finology/:category',
+ },
+ {
+ title: 'Most Viewed',
+ docs: 'https://docs.rsshub.app/en/finance.html#finology-insider',
+ source: '/most-viewed',
+ target: '/finology/most-viewed/monthly',
+ },
+ {
+ title: 'Trending Topic',
+ docs: 'https://docs.rsshub.app/en/finance.html#finology-insider',
+ source: ['/tag/:topic'],
+ target: '/finology/tag/:topic',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/finology/router.js b/lib/v2/finology/router.js
new file mode 100644
index 000000000..b4416b31c
--- /dev/null
+++ b/lib/v2/finology/router.js
@@ -0,0 +1,6 @@
+module.exports = (router) => {
+ router.get('/bullets', require('./bullets'));
+ router.get('/:category', require('./tag'));
+ router.get('/most-viewed/:time', require('./mostViewed'));
+ router.get('/tag/:topic', require('./tag'));
+};
diff --git a/lib/v2/finology/tag.js b/lib/v2/finology/tag.js
new file mode 100644
index 000000000..81ef88124
--- /dev/null
+++ b/lib/v2/finology/tag.js
@@ -0,0 +1,33 @@
+const logger = require('@/utils/logger');
+const { getItems } = require('./utils');
+
+module.exports = async (ctx) => {
+ const { topic, category } = ctx.params;
+ 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);
+ ctx.state.data = {
+ 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/v2/finology/utils.js b/lib/v2/finology/utils.js
new file mode 100644
index 000000000..259b02dd9
--- /dev/null
+++ b/lib/v2/finology/utils.js
@@ -0,0 +1,58 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+
+const getItems = async (ctx, url, extra) => {
+ const mainUrl = 'https://insider.finology.in';
+ const { data: response } = await got(url);
+ const $ = cheerio.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 ? parseDate(item.find('div.text-light p').first().text(), 'DD-MMM-YYYY') : '';
+ 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,
+ };
+ });
+
+ const items = (
+ await Promise.allSettled(
+ listItems.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const { data: response } = await got(item.link);
+ const $ = cheerio.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();
+ 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;
+};
+
+module.exports = { getItems };