Browse Source

added Chilecultura

Pablo Barrera Yaksic 2 months ago
parent
commit
9d66c92ca2

+ 3 - 1
.env.example

@@ -5,8 +5,9 @@ MASTODON_URL = "https://<mastodon-domain>/api/v1/"
 MASTODON_ACCESS_TOKEN = "<access-token>"
 IMG_PLACEHOLDER = "https://placehold.co/600x400"
 
+CHILECULTURA = "https://chilecultura.gob.cl/events/",
 DF = "https://www.df.cl/ultimasnoticias"
-ELCIUDADANO = "https://www.elciudadano.com/chile/"
+ELCIUDADANO = "https://www.elciudadano.com/"
 ELDESCONCIERTO = "https://eldesconcierto.cl"
 ELMOSTRADOR = "https://www.elmostrador.cl/categoria/dia/"
 EMOL = "https://www.emol.com"
@@ -15,6 +16,7 @@ LATERCERA = "https://www.latercera.com/canal/nacional/"
 THECLINIC = "https://www.theclinic.cl/lo-ultimo/"
 
 # KEYS
+MASTODON_KEY_CHILECULTURA = ""
 MASTODON_KEY_DF = ""
 MASTODON_KEY_ELCIUDADANO = ""
 MASTODON_KEY_ELDESCONCIERTO = ""

+ 2 - 0
src/config.ts

@@ -8,6 +8,7 @@ const config = {
   MASTODON_ACCESS_TOKEN: process.env.MASTODON_ACCESS_TOKEN ?? "",
   IMG_PLACEHOLDER: process.env.IMG_PLACEHOLDER ?? "https://placehold.co/600x400",
   // PORTALES
+  CHILECULTURA: process.env.CHILECULTURA ?? "https://chilecultura.gob.cl/events/",
   DF: process.env.DF ?? "https://www.df.cl/ultimasnoticias",
   ELCIUDADANO: process.env.ELCIUDADANO ?? "https://www.elciudadano.com/",
   ELDESCONCIERTO: process.env.ELDESCONCIERTO ?? "https://eldesconcierto.cl",
@@ -17,6 +18,7 @@ const config = {
   LATERCERA: process.env.LATERCERA ?? "https://www.latercera.com/canal/nacional/",
   THECLINIC: process.env.THECLINIC ?? "https://www.theclinic.cl/lo-ultimo/",
   // KEYS
+  MASTODON_KEY_CHILECULTURA: process.env.MASTODON_KEY_CHILECULTURA ?? "",
   MASTODON_KEY_DF: process.env.MASTODON_KEY_DF ?? "",
   MASTODON_KEY_ELCIUDADANO: process.env.MASTODON_KEY_ELCIUDADANO ?? "",
   MASTODON_KEY_ELDESCONCIERTO: process.env.MASTODON_KEY_ELDESCONCIERTO ?? "",

+ 3 - 1
src/enums/emojis.ts

@@ -1,7 +1,9 @@
 enum Emojis {
   LINK = "🔗",
   NEWS = "📰",
-  TAGS = "🏷️"
+  TAGS = "🏷️",
+  CALENDAR = "📆",
+  PIN = "📍"
 };
 
 export default Emojis

+ 2 - 1
src/index.ts

@@ -1,5 +1,6 @@
 import { type Context } from "aws-lambda";
 
+import { handler as chilecultura } from "./portales/chilecultura/handler";
 import { handler as df } from "./portales/df/handler";
 import { handler as elciudadano } from "./portales/elciudadano/handler";
 import { handler as eldesconcierto } from "./portales/eldesconcierto/handler";
@@ -24,7 +25,7 @@ const context: Context = {
   getRemainingTimeInMillis: () => 1
 };
 
-const portals = [df, elciudadano, eldesconcierto, elmostrador, emol, interferencia, latercera, theclinic];
+const portals = [chilecultura, df, elciudadano, eldesconcierto, elmostrador, emol, interferencia, latercera, theclinic];
 const cooldown = 10000; // 10 seconds
 
 async function main (): Promise<void> {

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

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

+ 23 - 0
src/portales/chilecultura/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 = "Chile Cultura";
+
+export const handler: Handler = new Portal(
+  name,
+  config.MASTODON_KEY_CHILECULTURA,
+  {
+    url: config.CHILECULTURA,
+    articlesSelector: "section.section-base-subsection#this_week_events .card-event, section.section-base-subsection#next_week_events .card-event",
+    titleSelector: "div.card-body a",
+    linkSelector: "div.card-body a",
+    contentSelector: "p.card-discipline, p.card-description-icon",
+    linkPrefix: "https://chilecultura.gob.cl",
+    scraperMethod: ScraperMethods.AXIOS,
+    cacheExpiration: 60 * 60 * 24 * 7, // 7 días
+    hashtags: ["ChileCultura", "Cartelera", "Panoramas", "Cultura", "Chile"]
+  }
+).getHandler();

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

@@ -16,7 +16,7 @@ export const handler: Handler = new Portal(
     linkSelector: "div.headline a",
     linkPrefix: "https://www.latercera.cl",
     scraperMethod: ScraperMethods.AXIOS,
-    cacheExpiration: 60 * 60 * 24 * 5, // días
+    cacheExpiration: 60 * 60 * 24 * 5, // 5 días
     hashtags: ["LaTercera", "LT", "Noticias"]
   }
 ).getHandler();

+ 17 - 0
src/portales/portal.ts

@@ -77,6 +77,23 @@ export default class Portal {
           message += `\n${Emojis.LINK} ${article.link}`;
         }
 
+        if (this._name.toUpperCase() == "Chile Cultura".toUpperCase()) {
+          // Icons Chilecultura
+          let regex = new RegExp(/\n(\d{1,2} \w{3})\s*\n?\s*-\s*(\d{1,2} \w{3})/);
+          message = message.replace("date_range", `${Emojis.CALENDAR} `);
+          message = message.replace(regex, (match, p1, p2) => {
+            return `${p1} - ${p2}`;
+          });
+          
+          message = message.replace("location_on", Emojis.PIN).replace(`${Emojis.PIN}\n`, `${Emojis.PIN} `);
+          
+          // Expresión regular para capturar el texto antes del 📆 seguido de una fecha
+          regex = new RegExp(/(.*?)📆 (\d{1,2} \w{3} - \d{1,2} \w{3})/);
+          message = message.replace(regex, (match, p1, p2) => {
+            return `🎭 ${p1}\n📆 ${p2}`;
+          });
+        }
+
         const mediaIds: any[] = [];
         if (article.image !== null && article.image !== undefined) {
           const media = await this._mastodonClient.v2.media.create({ file: article.image, description: article.title });