feat(visionias): add routes for vision IAS (#19552)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { Data, Route, DataItem } from '@/types';
|
||||
import { baseUrl } from './utils';
|
||||
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/dailySummary',
|
||||
example: '/visionias/dailySummary',
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['visionias.in/current-affairs/upsc-daily-news-summary'],
|
||||
target: '/dailySummary',
|
||||
},
|
||||
],
|
||||
name: 'Daily News Summary',
|
||||
maintainers: ['Rjnishant530'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(): Promise<Data> {
|
||||
const response = await ofetch(`${baseUrl}/current-affairs/upsc-daily-news-summary`);
|
||||
|
||||
const items = processNews(response);
|
||||
|
||||
return {
|
||||
title: 'Daily News Summary | Vision IAS',
|
||||
link: `${baseUrl}/current-affairs/upsc-daily-news-summary`,
|
||||
description:
|
||||
'Get concise and efficient summaries of key articles from prominent newspapers. Our daily news digest ensures quick reading and easy understanding, helping you stay informed about important events and developments without spending hours going through full articles. Perfect for focused and timely updates.',
|
||||
language: 'en',
|
||||
item: items,
|
||||
image: `${baseUrl}/current-affairs/images/news-today-logo.svg`,
|
||||
icon: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
logo: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
allowEmpty: true,
|
||||
};
|
||||
}
|
||||
|
||||
function processNews(page) {
|
||||
const $ = load(page);
|
||||
const items = $(`#quiz-start div[x-data="{ isExpanded: false }"]`)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const title = $(item).find('a>h5').text().trim();
|
||||
const content = $(item).find('a>div').html() ?? '';
|
||||
const link = $(item).find('div>p>a').attr('href') || '';
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
guid: link,
|
||||
description: content,
|
||||
} as DataItem;
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Data, Route } from '@/types';
|
||||
import { baseUrl, extractNews } from './utils';
|
||||
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/monthlyMagazine',
|
||||
example: '/visionias/monthlyMagazine',
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['visionias.in/current-affairs/monthly-magazine'],
|
||||
target: '/monthlyMagazine',
|
||||
},
|
||||
],
|
||||
name: 'Monthly Magazine',
|
||||
maintainers: ['Rjnishant530'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(): Promise<Data> {
|
||||
const response = await ofetch(`${baseUrl}/current-affairs/monthly-magazine`);
|
||||
|
||||
const items = await processNews(response);
|
||||
|
||||
return {
|
||||
title: 'Monthly Magazine | Vision IAS',
|
||||
link: `${baseUrl}/current-affairs/monthly-magazine`,
|
||||
description:
|
||||
'Monthly Magazine from Vision IAS provides a comprehensive overview of current affairs, covering significant events and developments across various sectors. It is designed to help aspirants stay updated with the latest happenings, enhancing their preparation for competitive exams.',
|
||||
language: 'en',
|
||||
item: items,
|
||||
image: `${baseUrl}/current-affairs/images/news-today-logo.svg`,
|
||||
icon: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
logo: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
allowEmpty: true,
|
||||
};
|
||||
}
|
||||
|
||||
async function processNews(page) {
|
||||
const $ = load(page);
|
||||
const divItems = $(`#monthly-table-of-content>div`).toArray();
|
||||
const linkItems = divItems.flatMap((item) => {
|
||||
const maintitle = $(item).find('button>div:nth-child(2) div.text-left').text().trim();
|
||||
return $(item)
|
||||
.find('div>ul>li')
|
||||
.toArray()
|
||||
.map((li) => {
|
||||
const itemTitle = $(li).find('a').text().trim();
|
||||
const link = $(li).find('a').attr('href')?.trim() || '';
|
||||
return {
|
||||
title: `${itemTitle} - ${maintitle}`,
|
||||
link: link.includes('https://') ? link : `${baseUrl}${link}`,
|
||||
};
|
||||
});
|
||||
});
|
||||
const newsPromises = await Promise.allSettled(linkItems.map((item) => extractNews(item, 'main > div > div.flex.flex-col> div.flex.flex-col.w-full.mt-10')));
|
||||
|
||||
return newsPromises.flatMap((news) => (news.status === 'fulfilled' ? (Array.isArray(news.value) ? news.value : [news.value]) : [{ title: 'Error Parse News' }]));
|
||||
}
|
||||
@@ -65,8 +65,8 @@ async function handler(ctx): Promise<Data> {
|
||||
language: 'en',
|
||||
item: items,
|
||||
image: `${baseUrl}/current-affairs/images/news-today-logo.svg`,
|
||||
icon: `${baseUrl}/current-affairs/favicon.ico`,
|
||||
logo: `${baseUrl}/current-affairs/favicon.ico`,
|
||||
icon: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
logo: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
allowEmpty: true,
|
||||
};
|
||||
}
|
||||
@@ -86,15 +86,5 @@ async function processCurrentNews(currentUrl) {
|
||||
};
|
||||
});
|
||||
const newsPromises = await Promise.allSettled(items.map((item) => extractNews(item, 'main > div > div.mt-6 > div.flex > div.flex.mt-6')));
|
||||
const finalItems: any = [];
|
||||
for (const news of newsPromises) {
|
||||
if (news.status === 'fulfilled') {
|
||||
finalItems.push(...(Array.isArray(news.value) ? news.value : [news.value]));
|
||||
} else {
|
||||
finalItems.push({
|
||||
title: 'Error Parse News',
|
||||
});
|
||||
}
|
||||
}
|
||||
return finalItems;
|
||||
return newsPromises.flatMap((news) => (news.status === 'fulfilled' ? (Array.isArray(news.value) ? news.value : [news.value]) : [{ title: 'Error Parse News' }]));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function extractNews(item, selector) {
|
||||
if (shortArticles.length !== 0) {
|
||||
const items = shortArticles.toArray().map((element) => {
|
||||
const mainDiv = $$(element);
|
||||
const title = mainDiv.find('a > div > h1').text().trim();
|
||||
const title = mainDiv.find('a > div > h2').text().trim();
|
||||
const id = mainDiv.find('a').attr('href');
|
||||
const htmlContent = extractArticle(mainDiv.html());
|
||||
const innerTags = mainDiv
|
||||
@@ -94,7 +94,7 @@ export async function extractNews(item, selector) {
|
||||
});
|
||||
}
|
||||
|
||||
function extractArticle(articleDiv, selectorString: string = '#article-content') {
|
||||
function extractArticle(articleDiv, selectorString: string = 'div.ck-content') {
|
||||
const $ = load(articleDiv, null, false);
|
||||
const articleDiv$ = $(articleDiv);
|
||||
const articleContent = articleDiv$.find(String(selectorString));
|
||||
|
||||
@@ -49,8 +49,8 @@ async function handler(ctx): Promise<Data> {
|
||||
language: 'en',
|
||||
item: itemsPromise.map((item) => (item.status === 'fulfilled' ? item.value : { title: 'Error Parse News' })),
|
||||
image: `${baseUrl}/current-affairs/images/weekly-focus-logo.svg`,
|
||||
icon: `${baseUrl}/current-affairs/favicon.ico`,
|
||||
logo: `${baseUrl}/current-affairs/favicon.ico`,
|
||||
icon: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
logo: `https://cdn.visionias.in/new-system-assets/images/home_page/home/vision-logo-footer.png`,
|
||||
allowEmpty: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user