Sfoglia il codice sorgente

Merge branch 'develop' of Mastodon/bots into main

Pablo Yaksic 1 settimana fa
parent
commit
cd0fa11c70

+ 1 - 0
.env.example

@@ -51,6 +51,7 @@ MASTODON_KEY_FASTCHECK = ""
 MASTODON_KEY_GLACIARESCHILENOS = ""
 MASTODON_KEY_INTERFERENCIA = ""
 MASTODON_KEY_LADERASUR = ""
+MASTODON_KEY_LANACION = ""
 MASTODON_KEY_LATERCERA = ""
 MASTODON_KEY_RESUMEN = ""
 MASTODON_KEY_SISMOLOGIA = ""

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "bot-noticias",
-  "version": "0.0.18",
+  "version": "0.0.19",
   "description": "Bot que busca noticias y las replica en mastodon.cl",
   "main": "dist/index.js",
   "scripts": {

+ 2 - 0
src/config.ts

@@ -31,6 +31,7 @@ const config = {
   GLACIARESCHILENOS: process.env.GLACIARESCHILENOS ?? "https://www.glaciareschilenos.org/articulos/",
   INTERFERENCIA: process.env.INTERFERENCIA ?? "https://interferencia.cl/",
   LADERASUR: process.env.LADERASUR ?? "https://laderasur.com/",
+  LANACION: process.env.LANACION ?? "https://www.lanacion.cl/",
   LATERCERA: process.env.LATERCERA ?? "https://www.latercera.com/canal/nacional/",
   RESUMEN: process.env.RESUMEN ?? "https://resumen.cl/",
   SISMOLOGIA: process.env.SISMOLOGIA ?? "https://www.sismologia.cl/index.html",
@@ -53,6 +54,7 @@ const config = {
   MASTODON_KEY_GLACIARESCHILENOS: process.env.MASTODON_KEY_GLACIARESCHILENOS ?? "",
   MASTODON_KEY_INTERFERENCIA: process.env.MASTODON_KEY_INTERFERENCIA ?? "",
   MASTODON_KEY_LADERASUR: process.env.MASTODON_KEY_LADERASUR ?? "",
+  MASTODON_KEY_LANACION: process.env.MASTODON_KEY_LANACION ?? "",
   MASTODON_KEY_LATERCERA: process.env.MASTODON_KEY_LATERCERA ?? "",
   MASTODON_KEY_RESUMEN: process.env.MASTODON_KEY_RESUMEN ?? "",
   MASTODON_KEY_SISMOLOGIA: process.env.MASTODON_KEY_SISMOLOGIA ?? "",

+ 2 - 2
src/portales/biobiochile/handler.ts

@@ -11,10 +11,10 @@ export const handler: Handler = new Portal(
   config.MASTODON_KEY_BIOBIOCHILE,
   {
     url: config.BIOBIOCHILE,
-    articlesSelector: "article.main-article, article.article-highlights, article.article-horizontal, article.vertical, article.article-highlights-aside",
+    articlesSelector: "article",
     titleSelector: ".article-title:first",
     linkSelector: "a",
-    scraperMethod: ScraperMethods.AXIOS,
+    scraperMethod: ScraperMethods.PUPPETEER,
     hashtags: ["BioBioChile", "Noticias"]
   }
 ).getHandler();

+ 1 - 1
src/portales/cooperativa/handler.ts

@@ -14,7 +14,7 @@ export const handler: Handler = new Portal(
     articlesSelector: "section > div:nth-of-type(3) article",
     titleSelector: "h1.titular-noticia, h3.titular-noticia",
     linkPrefix: "https://www.cooperativa.cl",
-    linkSelector: "article > a:nth-of-type(2)",
+    linkSelector: "a:has(h1.titular-noticia), a:has(h3.titular-noticia)",
     scraperMethod: ScraperMethods.AXIOS,
     hashtags: ["Noticias", "País", "Deportes", "Mundo"],
     cacheExpiration: 60 * 60 * 24 * 30, // 30 días

+ 4 - 0
src/portales/lanacion/definition.yml

@@ -0,0 +1,4 @@
+lanacion:
+  handler: ./src/portales/lanacion/handler.handler
+  events: 
+    - schedule: rate(1 hour)

+ 23 - 0
src/portales/lanacion/handler.ts

@@ -0,0 +1,23 @@
+import { type Handler } from "aws-lambda";
+
+import config from "../../config";
+import Portal from "../portal";
+import ScraperMethods from "../../enums/scraper-methods";
+
+const name = "La Nación";
+
+export const handler: Handler = new Portal(
+  name,
+  config.MASTODON_KEY_LANACION,
+  {
+    url: config.LANACION,
+    articlesSelector: ".td_module_2, .td_module_6, .td_module_10, .td_module_mx1, .td_module_mx5, .td_module_flex_6, .td_module_flex_7",
+    titleSelector: ".entry-title.td-module-title a",
+    linkSelector: ".td-image-wrap",
+    contentSelector: ".td-excerpt",
+    imageSelector: ".entry-thumb",
+    scraperMethod: ScraperMethods.AXIOS,
+    maxArticles: 20,
+    hashtags: ["LaNacion", "Noticias"]
+  }
+).getHandler();

+ 8 - 1
src/utils/scraper-articles.ts

@@ -48,7 +48,14 @@ export default class ScraperArticles {
 
   private getLink(article: AnyNode): string {
     const selector = this._options.linkSelector ?? "";
-    const url = selector !== "" ? this.getProperty(article, selector, Props.LINK) : this._options.url
+    let url = selector !== "" ? this.getProperty(article, selector, Props.LINK) : this._options.url
+
+    // Fallback: when the article itself is wrapped by an anchor (e.g. BioBioChile)
+    // and the configured linkSelector does not find a descendant link.
+    if (!url && selector !== "") {
+      const $ = load(article);
+      url = $(article).closest("a").attr("href") ?? "";
+    }
 
     return !this.isValidUrl(url) && this._options.linkPrefix !== undefined
       ? (this._options.linkPrefix + url.trim()).trim()