Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add publico.es #18242

Merged
merged 5 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions lib/routes/publico/ciencias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';

import getItems from './items-processor';

export const route: Route = {
path: '/ciencias/:subsection?',
adrianrico97 marked this conversation as resolved.
Show resolved Hide resolved
parameters: {
subsection: {
description: "Filter by subsection. Check the subsections available on the newspaper's website.",
},
},
categories: ['traditional-media'],
example: '/publico/ciencias',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['publico.es/ciencias'],
target: '/ciencias',
},
],
name: 'Ciencias',
maintainers: ['adrianrico97'],
handler,
};

async function handler(ctx) {
const { subsection } = ctx.req.param();

const rootUrl = 'https://www.publico.es';
const currentUrl = subsection ? `${rootUrl}/ciencias/${subsection}` : `${rootUrl}/ciencias`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);
const title = $('.article-section h1').text();
const items = getItems($);

return {
title: `${title} | Público`,
link: currentUrl,
item: items,
};
}
55 changes: 55 additions & 0 deletions lib/routes/publico/culturas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';

import getItems from './items-processor';

export const route: Route = {
path: '/culturas/:subsection?',
adrianrico97 marked this conversation as resolved.
Show resolved Hide resolved
parameters: {
subsection: {
description: "Filter by subsection. Check the subsections available on the newspaper's website.",
},
},
categories: ['traditional-media'],
example: '/publico/culturas',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['publico.es/culturas'],
target: '/culturas',
},
],
name: 'Culturas',
maintainers: ['adrianrico97'],
handler,
};

async function handler(ctx) {
const { subsection } = ctx.req.param();

const rootUrl = 'https://www.publico.es';
const currentUrl = subsection ? `${rootUrl}/culturas/${subsection}` : `${rootUrl}/culturas`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);
const title = $('.article-section h1').text();
const items = getItems($);

return {
title: `${title} | Público`,
link: currentUrl,
item: items,
};
}
55 changes: 55 additions & 0 deletions lib/routes/publico/economia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';

import getItems from './items-processor';

export const route: Route = {
path: '/economia/:subsection?',
adrianrico97 marked this conversation as resolved.
Show resolved Hide resolved
parameters: {
subsection: {
description: "Filter by subsection. Check the subsections available on the newspaper's website.",
},
},
categories: ['traditional-media'],
example: '/publico/economia',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['publico.es/economia'],
target: '/economia',
},
],
name: 'Economia',
maintainers: ['adrianrico97'],
handler,
};

async function handler(ctx) {
const { subsection } = ctx.req.param();

const rootUrl = 'https://www.publico.es';
const currentUrl = subsection ? `${rootUrl}/economia/${subsection}` : `${rootUrl}/economia`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);
const title = $('.article-section h1').text();
const items = getItems($);

return {
title: `${title} | Público`,
link: currentUrl,
item: items,
};
}
55 changes: 55 additions & 0 deletions lib/routes/publico/internacional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';

import getItems from './items-processor';

export const route: Route = {
path: '/internacional/:subsection?',
adrianrico97 marked this conversation as resolved.
Show resolved Hide resolved
parameters: {
subsection: {
description: "Filter by subsection. Check the subsections available on the newspaper's website.",
},
},
categories: ['traditional-media'],
example: '/publico/internacional',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['publico.es/internacional'],
target: '/internacional',
},
],
name: 'Internacional',
maintainers: ['adrianrico97'],
handler,
};

async function handler(ctx) {
const { subsection } = ctx.req.param();

const rootUrl = 'https://www.publico.es';
const currentUrl = subsection ? `${rootUrl}/internacional/${subsection}` : `${rootUrl}/internacional`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);
const title = $('.article-section h1').text();
const items = getItems($);

return {
title: `${title} | Público`,
link: currentUrl,
item: items,
};
}
20 changes: 20 additions & 0 deletions lib/routes/publico/items-processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default function getItems(data) {
const items = data('.category-list li')
.toArray()
.map((item) => {
item = data(item);
const title = item.find('h2').text();
const link = item.find('a').attr('href');
const author = item.find('p').text();
const image = item.find('picture img').attr('src');

return {
title,
link,
description: `<img src="${image}" alt="${title}">`,
author,
};
});

return items;
}
55 changes: 55 additions & 0 deletions lib/routes/publico/mujer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';

import getItems from './items-processor';

export const route: Route = {
path: '/mujer/:subsection?',
adrianrico97 marked this conversation as resolved.
Show resolved Hide resolved
parameters: {
subsection: {
description: "Filter by subsection. Check the subsections available on the newspaper's website.",
},
},
categories: ['traditional-media'],
example: '/publico/mujer',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['publico.es/mujer'],
target: '/mujer',
},
],
name: 'Mujer',
maintainers: ['adrianrico97'],
handler,
};

async function handler(ctx) {
const { subsection } = ctx.req.param();

const rootUrl = 'https://www.publico.es';
const currentUrl = subsection ? `${rootUrl}/mujer/${subsection}` : `${rootUrl}/mujer`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);
const title = $('.article-section h1').text();
const items = getItems($);

return {
title: `${title} | Público`,
link: currentUrl,
item: items,
};
}
6 changes: 6 additions & 0 deletions lib/routes/publico/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Público',
url: 'publico.es',
};
55 changes: 55 additions & 0 deletions lib/routes/publico/opinion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';

import getItems from './items-processor';

export const route: Route = {
path: '/opinion/:subsection?',
adrianrico97 marked this conversation as resolved.
Show resolved Hide resolved
parameters: {
subsection: {
description: "Filter by subsection. Check the subsections available on the newspaper's website.",
},
},
categories: ['traditional-media'],
example: '/publico/opinion',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['publico.es/opinion'],
target: '/opinion',
},
],
name: 'Opinión',
maintainers: ['adrianrico97'],
handler,
};

async function handler(ctx) {
const { subsection } = ctx.req.param();

const rootUrl = 'https://www.publico.es';
const currentUrl = subsection ? `${rootUrl}/opinion/${subsection}` : `${rootUrl}/opinion`;

const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);
const title = $('.article-section h1').text();
const items = getItems($);

return {
title: `${title} | Público`,
link: currentUrl,
item: items,
};
}
Loading