Bläddra i källkod

Merge branch 'develop' of Mastodon/bots into main

Pablo Yaksic 1 vecka sedan
förälder
incheckning
d9fa40d698

+ 6 - 0
.env.example

@@ -17,6 +17,7 @@ MASTODON_DB_DATABASE = "mastodon"
 24HORAS = "https://www.24horas.cl/"
 ADNRADIO = "https://www.adnradio.cl/"
 BIOBIOCHILE = "https://www.biobiochile.cl/"
+CAMBIO21 = "https://cambio21.cl/"
 CHILECULTURA = "https://chilecultura.gob.cl/events/"
 CIPER = "https://www.ciperchile.cl/actualidad/"
 CODEXVERDE = "https://codexverde.cl/"
@@ -32,6 +33,8 @@ FASTCHECK = "https://www.fastcheck.cl/"
 GLACIARESCHILENOS = "https://www.glaciareschilenos.org/articulos/"
 INTERFERENCIA = "https://interferencia.cl/"
 LADERASUR = "https://laderasur.com/articulos-2/"
+LAHORA = "https://lahora.cl/"
+LAVOZDELOSQUESOBRAN = "https://lavozdelosquesobran.cl/"
 LATERCERA = "https://www.latercera.com/canal/nacional/"
 METEORED = "https://www.meteored.cl/"
 RESUMEN = "https://resumen.cl/"
@@ -43,6 +46,7 @@ THECLINIC = "https://www.theclinic.cl/lo-ultimo/"
 MASTODON_KEY_24HORAS = ""
 MASTODON_KEY_ADNRADIO = ""
 MASTODON_KEY_BIOBIOCHILE = ""
+MASTODON_KEY_CAMBIO21 = ""
 MASTODON_KEY_CHILECULTURA = ""
 MASTODON_KEY_CIPER = ""
 MASTODON_KEY_CNNCHILE = ""
@@ -58,6 +62,8 @@ MASTODON_KEY_FASTCHECK = ""
 MASTODON_KEY_GLACIARESCHILENOS = ""
 MASTODON_KEY_INTERFERENCIA = ""
 MASTODON_KEY_LADERASUR = ""
+MASTODON_KEY_LAHORA = ""
+MASTODON_KEY_LAVOZDELOSQUESOBRAN = ""
 MASTODON_KEY_LANACION = ""
 MASTODON_KEY_LATERCERA = ""
 MASTODON_KEY_METEORED = ""

+ 1 - 1
package.json

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

+ 6 - 0
src/config.ts

@@ -18,6 +18,7 @@ const config = {
   HORAS24: process.env["24HORAS"] ?? "https://www.24horas.cl/",
   ADNRADIO: process.env.ADNRADIO ?? "https://www.adnradio.cl/",
   BIOBIOCHILE: process.env.BIOBIOCHILE ?? "https://www.biobiochile.cl/",
+  CAMBIO21: process.env.CAMBIO21 ?? "https://cambio21.cl/",
   CHILECULTURA: process.env.CHILECULTURA ?? "https://chilecultura.gob.cl/",
   CIPER: process.env.CIPER ?? "https://www.ciperchile.cl/actualidad/",
   CODEXVERDE: process.env.CODEXVERDE ?? "https://codexverde.cl/",
@@ -34,6 +35,8 @@ 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/",
+  LAHORA: process.env.LAHORA ?? "https://lahora.cl/",
+  LAVOZDELOSQUESOBRAN: process.env.LAVOZDELOSQUESOBRAN ?? "https://lavozdelosquesobran.cl/",
   LANACION: process.env.LANACION ?? "https://www.lanacion.cl/",
   LATERCERA: process.env.LATERCERA ?? "https://www.latercera.com/canal/nacional/",
   METEORED: process.env.METEORED ?? "https://www.meteored.cl/",
@@ -45,6 +48,7 @@ const config = {
   MASTODON_KEY_24HORAS: process.env.MASTODON_KEY_24HORAS ?? "",
   MASTODON_KEY_ADNRADIO: process.env.MASTODON_KEY_ADNRADIO ?? "",
   MASTODON_KEY_BIOBIOCHILE: process.env.MASTODON_KEY_BIOBIOCHILE ?? "",
+  MASTODON_KEY_CAMBIO21: process.env.MASTODON_KEY_CAMBIO21 ?? "",
   MASTODON_KEY_CHILECULTURA: process.env.MASTODON_KEY_CHILECULTURA ?? "",
   MASTODON_KEY_CIPER: process.env.MASTODON_KEY_CIPER ?? "",
   MASTODON_KEY_CODEXVERDE: process.env.MASTODON_KEY_CODEXVERDE ?? "",
@@ -61,6 +65,8 @@ 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_LAHORA: process.env.MASTODON_KEY_LAHORA ?? "",
+  MASTODON_KEY_LAVOZDELOSQUESOBRAN: process.env.MASTODON_KEY_LAVOZDELOSQUESOBRAN ?? "",
   MASTODON_KEY_LANACION: process.env.MASTODON_KEY_LANACION ?? "",
   MASTODON_KEY_LATERCERA: process.env.MASTODON_KEY_LATERCERA ?? "",
   MASTODON_KEY_METEORED: process.env.MASTODON_KEY_METEORED ?? "",

+ 3 - 1
src/enums/props.ts

@@ -1,7 +1,9 @@
 enum Props {
   TEXT = "text",
   LINK = "href",
-  IMAGE = "src"
+  IMAGE = "src",
+  DATA_IMAGE = "data-src",
+  STYLE = "style"
 };
 
 export default Props

+ 6 - 0
src/index.ts

@@ -5,6 +5,7 @@ import config from "./config";
 import { handler as horas24 } from "./portales/24horas/handler";
 import { handler as adnradio } from "./portales/adnradio/handler";
 import { handler as biobiochile } from "./portales/biobiochile/handler";
+import { handler as cambio21 } from "./portales/cambio21/handler";
 import { handler as chilecultura } from "./portales/chilecultura/handler";
 import { handler as ciper } from "./portales/ciper/handler";
 import { handler as cnnchile } from "./portales/cnnchile/handler";
@@ -21,6 +22,8 @@ import { handler as fastcheck } from "./portales/fastcheck/handler";
 // import { handler as glaciareschilenos } from "./portales/glaciareschilenos/handler";
 import { handler as interferencia } from "./portales/interferencia/handler";
 import { handler as laderasur } from "./portales/laderasur/handler";
+import { handler as lahora } from "./portales/lahora/handler";
+import { handler as lavozdelosquesobran } from "./portales/lavozdelosquesobran/handler";
 import { handler as lanacion } from "./portales/lanacion/handler";
 import { handler as latercera } from "./portales/latercera/handler";
 import { handler as meteored } from "./portales/meteored/handler";
@@ -48,6 +51,7 @@ const portalsHandlers = {
   "24horas": horas24,
   "adnradio": adnradio,
   "biobiochile": biobiochile,
+  "cambio21": cambio21,
   "chilecultura": chilecultura,
   "ciper": ciper,
   "cnnchile": cnnchile,
@@ -64,6 +68,8 @@ const portalsHandlers = {
   // "glaciareschilenos": glaciareschilenos,
   "interferencia": interferencia,
   "laderasur": laderasur,
+  "lahora": lahora,
+  "lavozdelosquesobran": lavozdelosquesobran,
   "lanacion": lanacion,
   "latercera": latercera,
   "meteored": meteored,

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

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

+ 22 - 0
src/portales/cambio21/handler.ts

@@ -0,0 +1,22 @@
+import { type Handler } from "aws-lambda";
+
+import config from "../../config";
+import Portal from "../portal";
+import ScraperMethods from "../../enums/scraper-methods";
+
+const name = "Cambio21";
+
+export const handler: Handler = new Portal(
+  name,
+  config.MASTODON_KEY_CAMBIO21,
+  {
+    url: config.CAMBIO21,
+    articlesSelector: ".news-post.image-post, .news-post.video-post",
+    titleSelector: "h2 a",
+    linkSelector: "h2 a",
+    imageSelector: "img",
+    scraperMethod: ScraperMethods.AXIOS,
+    maxArticles: 20,
+    hashtags: ["Cambio21", "Noticias"]
+  }
+).getHandler();

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

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

+ 24 - 0
src/portales/lahora/handler.ts

@@ -0,0 +1,24 @@
+import { type Handler } from "aws-lambda";
+
+import config from "../../config";
+import Portal from "../portal";
+import ScraperMethods from "../../enums/scraper-methods";
+
+const name = "La Hora";
+
+export const handler: Handler = new Portal(
+  name,
+  config.MASTODON_KEY_LAHORA,
+  {
+    url: config.LAHORA,
+    articlesSelector: ".slider-single, .home-featured article.row, .block-tab-item .post-thumb, .loop-grid .col-lg-4, .post-carausel-2 .col, .post-carausel-3 .col",
+    titleSelector: ".post-title a",
+    linkSelector: ".post-title a",
+    contentSelector: "p.excerpt, p.text-limit-2-row",
+    imageSelector: "img[data-src], .img-hover-slide",
+    linkPrefix: "https://lahora.cl",
+    scraperMethod: ScraperMethods.AXIOS,
+    maxArticles: 20,
+    hashtags: ["LaHora", "Noticias"]
+  }
+).getHandler();

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

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

+ 23 - 0
src/portales/lavozdelosquesobran/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 Voz de los Que Sobran";
+
+export const handler: Handler = new Portal(
+  name,
+  config.MASTODON_KEY_LAVOZDELOSQUESOBRAN,
+  {
+    url: config.LAVOZDELOSQUESOBRAN,
+    articlesSelector: ".lvqs-hero-cnn-main, .lvqs-hero-cnn-sub, .lvqs-card",
+    titleSelector: "h2 a, h3 a, .lvqs-card-title a",
+    linkSelector: "h2 a, h3 a, .lvqs-card-title a",
+    contentSelector: ".lvqs-hero-cnn-excerpt, .lvqs-card-excerpt",
+    imageSelector: "img[data-src], img",
+    scraperMethod: ScraperMethods.AXIOS,
+    maxArticles: 20,
+    hashtags: ["LaVozDeLosQueSobran", "Noticias"]
+  }
+).getHandler();

+ 15 - 0
src/utils/scraper-articles.ts

@@ -67,6 +67,21 @@ export default class ScraperArticles {
     const selector = this._options.imageSelector ?? "";
     let imgUrl = selector !== "" ? this.getProperty(article, selector, Props.IMAGE) : "";
 
+    if (selector !== "") {
+      const dataSrcUrl = this.getProperty(article, selector, Props.DATA_IMAGE);
+      if (dataSrcUrl !== "") {
+        imgUrl = dataSrcUrl;
+      }
+
+      if (imgUrl === "") {
+        const styleValue = this.getProperty(article, selector, Props.STYLE);
+        const backgroundImageMatch = styleValue.match(/background-image:\s*url\((['"]?)([^'"]+)\1\)/);
+        if (backgroundImageMatch != null) {
+          imgUrl = backgroundImageMatch[2];
+        }
+      }
+    }
+
     if (imgUrl !== "") {
       if (!this.isValidUrl(imgUrl) && this._options.imagePrefix) {
         imgUrl = this._options.imagePrefix + imgUrl.trim();