Bladeren bron

Added hashtags

Pablo Barrera Yaksic 2 maanden geleden
bovenliggende
commit
2231fab581

+ 2 - 1
src/enums/emojis.ts

@@ -1,6 +1,7 @@
 enum Emojis {
   LINK = "🔗",
-  NEWS = "📰"
+  NEWS = "📰",
+  TAGS = "🏷️"
 };
 
 export default Emojis

+ 2 - 1
src/interfaces/scaper-articles-options.ts

@@ -10,6 +10,7 @@ export interface IScraperArticlesOptions {
   imageSelector?: string
   authorSelector?: string
   dateSelector?: string
-  scraperMethod: ScraperMethods,
+  scraperMethod: ScraperMethods
   cacheExpiration?: number
+  hashtags?: Array<string>
 };

+ 2 - 1
src/portales/df/handler.ts

@@ -14,6 +14,7 @@ export const handler: Handler = new Portal(
     articlesSelector: "article",
     titleSelector: "h3 a",
     linkSelector: "h3 a",
-    scraperMethod: ScraperMethods.AXIOS
+    scraperMethod: ScraperMethods.AXIOS,
+    hashtags: ["DiarioFinanciero", "DF", "DFMas", "Noticias"]
   }
 ).getHandler();

+ 2 - 1
src/portales/elciudadano/handler.ts

@@ -17,6 +17,7 @@ export const handler: Handler = new Portal(
     articlesSelector: "article",
     titleSelector: "h3",
     linkSelector: "a",
-    scraperMethod: ScraperMethods.AXIOS
+    scraperMethod: ScraperMethods.AXIOS,
+    hashtags: ["ElCiudadano", "Noticias"]
   }
 ).getHandler();

+ 2 - 1
src/portales/eldesconcierto/handler.ts

@@ -15,6 +15,7 @@ export const handler: Handler = new Portal(
     titleSelector: "h2:first, h3:first",
     linkSelector: "a",
     linkPrefix: config.ELDESCONCIERTO,
-    scraperMethod: ScraperMethods.AXIOS
+    scraperMethod: ScraperMethods.AXIOS,
+    hashtags: ["ElDesconcierto", "Noticias"]
   }
 ).getHandler();

+ 2 - 1
src/portales/elmostrador/handler.ts

@@ -14,6 +14,7 @@ export const handler: Handler = new Portal(
     articlesSelector: "div.d-section__body div.d-tag-card",
     titleSelector: "h4",
     linkSelector: "h4 a",
-    scraperMethod: ScraperMethods.AXIOS
+    scraperMethod: ScraperMethods.AXIOS,
+    hashtags: ["ElMostrador", "Noticias"]
   }
 ).getHandler();

+ 2 - 1
src/portales/emol/handler.ts

@@ -15,6 +15,7 @@ export const handler: Handler = new Portal(
     titleSelector: "h1, h3, div.contenedor-titulo a",
     linkSelector: "h1 a, h3 a, div.contenedor-titulo a",
     linkPrefix: config.EMOL,
-    scraperMethod: ScraperMethods.AXIOS
+    scraperMethod: ScraperMethods.AXIOS,
+    hashtags: ["Emol", "ElMercurioOnline", "ElMercurio", "Noticias"]
   }
 ).getHandler();

+ 2 - 1
src/portales/interferencia/handler.ts

@@ -17,6 +17,7 @@ export const handler: Handler = new Portal(
     linkSelector: "div.views-field-title a",
     linkPrefix: "https://interferencia.cl",
     scraperMethod: ScraperMethods.AXIOS,
-    cacheExpiration: 60 * 60 * 24 * 7 // 7 días
+    cacheExpiration: 60 * 60 * 24 * 7, // 7 días
+    hashtags: ["Interferencia", "Noticias"]
   }
 ).getHandler();

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

@@ -16,6 +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, // días
+    hashtags: ["LaTercera", "LT", "Noticias"]
   }
 ).getHandler();

+ 10 - 1
src/portales/portal.ts

@@ -53,6 +53,15 @@ export default class Portal {
           continue;
         }
 
+        // Adding hashtags if there is
+        if (this._scraperArticlesOptions.hashtags) {
+          message += `\n${Emojis.TAGS} ` ;
+          this._scraperArticlesOptions.hashtags.forEach(hashtag => {
+            message += "#" + hashtag + " "
+          });
+        }
+        message.trimEnd();
+
         // To avoid publiposts (I'm lookint at you La Tercera >:-|)
         if (article.link.includes("publirreportajes")) {
           continue;
@@ -78,7 +87,7 @@ export default class Portal {
 
         await this._mastodonClient.v1.statuses.create({ status: message, mediaIds });
         await this._redisClient.store(
-          article.link, 
+          article.link.trim(), 
           date, 
           { EX: this._scraperArticlesOptions.cacheExpiration ? this._scraperArticlesOptions.cacheExpiration : 60 * 60 * 24 }
         ); // EX: 24 hrs expiration

+ 2 - 1
src/portales/theclinic/handler.ts

@@ -15,6 +15,7 @@ export const handler: Handler = new Portal(
     titleSelector: "div.titulares h2 a",
     linkSelector: "div.titulares h2 a",
     imageSelector: "div.imagen-post img",
-    scraperMethod: ScraperMethods.PUPPETEER
+    scraperMethod: ScraperMethods.PUPPETEER,
+    hashtags: ["TheClinic", "Noticias"]
   }
 ).getHandler();