浏览代码

added La Hora

Pablo 1 周之前
父节点
当前提交
0cba143209
共有 8 个文件被更改,包括 45 次插入2 次删除
  1. 2 0
      .env.example
  2. 1 1
      package.json
  3. 2 0
      src/config.ts
  4. 2 1
      src/enums/props.ts
  5. 2 0
      src/index.ts
  6. 4 0
      src/portales/lahora/definition.yml
  7. 24 0
      src/portales/lahora/handler.ts
  8. 8 0
      src/utils/scraper-articles.ts

+ 2 - 0
.env.example

@@ -33,6 +33,7 @@ FASTCHECK = "https://www.fastcheck.cl/"
 GLACIARESCHILENOS = "https://www.glaciareschilenos.org/articulos/"
 GLACIARESCHILENOS = "https://www.glaciareschilenos.org/articulos/"
 INTERFERENCIA = "https://interferencia.cl/"
 INTERFERENCIA = "https://interferencia.cl/"
 LADERASUR = "https://laderasur.com/articulos-2/"
 LADERASUR = "https://laderasur.com/articulos-2/"
+LAHORA = "https://lahora.cl/"
 LAVOZDELOSQUESOBRAN = "https://lavozdelosquesobran.cl/"
 LAVOZDELOSQUESOBRAN = "https://lavozdelosquesobran.cl/"
 LATERCERA = "https://www.latercera.com/canal/nacional/"
 LATERCERA = "https://www.latercera.com/canal/nacional/"
 METEORED = "https://www.meteored.cl/"
 METEORED = "https://www.meteored.cl/"
@@ -61,6 +62,7 @@ MASTODON_KEY_FASTCHECK = ""
 MASTODON_KEY_GLACIARESCHILENOS = ""
 MASTODON_KEY_GLACIARESCHILENOS = ""
 MASTODON_KEY_INTERFERENCIA = ""
 MASTODON_KEY_INTERFERENCIA = ""
 MASTODON_KEY_LADERASUR = ""
 MASTODON_KEY_LADERASUR = ""
+MASTODON_KEY_LAHORA = ""
 MASTODON_KEY_LAVOZDELOSQUESOBRAN = ""
 MASTODON_KEY_LAVOZDELOSQUESOBRAN = ""
 MASTODON_KEY_LANACION = ""
 MASTODON_KEY_LANACION = ""
 MASTODON_KEY_LATERCERA = ""
 MASTODON_KEY_LATERCERA = ""

+ 1 - 1
package.json

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

+ 2 - 0
src/config.ts

@@ -35,6 +35,7 @@ const config = {
   GLACIARESCHILENOS: process.env.GLACIARESCHILENOS ?? "https://www.glaciareschilenos.org/articulos/",
   GLACIARESCHILENOS: process.env.GLACIARESCHILENOS ?? "https://www.glaciareschilenos.org/articulos/",
   INTERFERENCIA: process.env.INTERFERENCIA ?? "https://interferencia.cl/",
   INTERFERENCIA: process.env.INTERFERENCIA ?? "https://interferencia.cl/",
   LADERASUR: process.env.LADERASUR ?? "https://laderasur.com/",
   LADERASUR: process.env.LADERASUR ?? "https://laderasur.com/",
+  LAHORA: process.env.LAHORA ?? "https://lahora.cl/",
   LAVOZDELOSQUESOBRAN: process.env.LAVOZDELOSQUESOBRAN ?? "https://lavozdelosquesobran.cl/",
   LAVOZDELOSQUESOBRAN: process.env.LAVOZDELOSQUESOBRAN ?? "https://lavozdelosquesobran.cl/",
   LANACION: process.env.LANACION ?? "https://www.lanacion.cl/",
   LANACION: process.env.LANACION ?? "https://www.lanacion.cl/",
   LATERCERA: process.env.LATERCERA ?? "https://www.latercera.com/canal/nacional/",
   LATERCERA: process.env.LATERCERA ?? "https://www.latercera.com/canal/nacional/",
@@ -64,6 +65,7 @@ const config = {
   MASTODON_KEY_GLACIARESCHILENOS: process.env.MASTODON_KEY_GLACIARESCHILENOS ?? "",
   MASTODON_KEY_GLACIARESCHILENOS: process.env.MASTODON_KEY_GLACIARESCHILENOS ?? "",
   MASTODON_KEY_INTERFERENCIA: process.env.MASTODON_KEY_INTERFERENCIA ?? "",
   MASTODON_KEY_INTERFERENCIA: process.env.MASTODON_KEY_INTERFERENCIA ?? "",
   MASTODON_KEY_LADERASUR: process.env.MASTODON_KEY_LADERASUR ?? "",
   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_LAVOZDELOSQUESOBRAN: process.env.MASTODON_KEY_LAVOZDELOSQUESOBRAN ?? "",
   MASTODON_KEY_LANACION: process.env.MASTODON_KEY_LANACION ?? "",
   MASTODON_KEY_LANACION: process.env.MASTODON_KEY_LANACION ?? "",
   MASTODON_KEY_LATERCERA: process.env.MASTODON_KEY_LATERCERA ?? "",
   MASTODON_KEY_LATERCERA: process.env.MASTODON_KEY_LATERCERA ?? "",

+ 2 - 1
src/enums/props.ts

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

+ 2 - 0
src/index.ts

@@ -22,6 +22,7 @@ import { handler as fastcheck } from "./portales/fastcheck/handler";
 // import { handler as glaciareschilenos } from "./portales/glaciareschilenos/handler";
 // import { handler as glaciareschilenos } from "./portales/glaciareschilenos/handler";
 import { handler as interferencia } from "./portales/interferencia/handler";
 import { handler as interferencia } from "./portales/interferencia/handler";
 import { handler as laderasur } from "./portales/laderasur/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 lavozdelosquesobran } from "./portales/lavozdelosquesobran/handler";
 import { handler as lanacion } from "./portales/lanacion/handler";
 import { handler as lanacion } from "./portales/lanacion/handler";
 import { handler as latercera } from "./portales/latercera/handler";
 import { handler as latercera } from "./portales/latercera/handler";
@@ -67,6 +68,7 @@ const portalsHandlers = {
   // "glaciareschilenos": glaciareschilenos,
   // "glaciareschilenos": glaciareschilenos,
   "interferencia": interferencia,
   "interferencia": interferencia,
   "laderasur": laderasur,
   "laderasur": laderasur,
+  "lahora": lahora,
   "lavozdelosquesobran": lavozdelosquesobran,
   "lavozdelosquesobran": lavozdelosquesobran,
   "lanacion": lanacion,
   "lanacion": lanacion,
   "latercera": latercera,
   "latercera": latercera,

+ 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();

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

@@ -72,6 +72,14 @@ export default class ScraperArticles {
       if (dataSrcUrl !== "") {
       if (dataSrcUrl !== "") {
         imgUrl = 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 (imgUrl !== "") {