Skip to content

Commit

Permalink
feat(route): add publico.es (#18242)
Browse files Browse the repository at this point in the history
* Add new route: Spanish newspaper publico.es

* Add new route: Spanish newspaper publico.es (II)

* Add new route: Spanish newspaper publico.es (III)

* Add new route: Spanish newspaper publico.es (fix)

* Add new route: Spanish newspaper publico.es (fixes II)
  • Loading branch information
adrianrico97 authored Feb 6, 2025
1 parent d2d3472 commit 4fb2b3e
Show file tree
Hide file tree
Showing 12 changed files with 563 additions and 0 deletions.
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?',
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?',
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?',
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?',
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?',
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?',
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

0 comments on commit 4fb2b3e

Please sign in to comment.