소스 검색

added contrapoder

Pablo Barrera Yaksic 1 주 전
부모
커밋
e7bbb4beca
4개의 변경된 파일36개의 추가작업 그리고 7개의 파일을 삭제
  1. 2 0
      src/config.ts
  2. 10 7
      src/index.ts
  3. 4 0
      src/portales/contrapoder/definition.yml
  4. 20 0
      src/portales/contrapoder/handler.ts

+ 2 - 0
src/config.ts

@@ -12,6 +12,7 @@ const config = {
   CHILECULTURA: process.env.CHILECULTURA ?? "https://chilecultura.gob.cl/",
   CIPER: process.env.CIPER ?? "https://www.ciperchile.cl/actualidad/",
   CODEXVERDE: process.env.CODEXVERDE ?? "https://codexverde.cl/",
+  CONTRAPODER: process.env.CONTRAPODER ?? "https://contrapoderchile.cl/category/portada/",
   // COOPERATIVA: process.env.COOPERATIVA ?? "https://cooperativa.cl/noticias/site/cache/nroedic/todas/",
   DF: process.env.DF ?? "https://www.df.cl/ultimasnoticias",
   ELCIUDADANO: process.env.ELCIUDADANO ?? "https://www.elciudadano.com/chile/",
@@ -31,6 +32,7 @@ const config = {
   MASTODON_KEY_CHILECULTURA: process.env.MASTODON_KEY_CHILECULTURA ?? "",
   MASTODON_KEY_CIPER: process.env.MASTODON_KEY_CIPER ?? "",
   MASTODON_KEY_CODEXVERDE: process.env.MASTODON_KEY_CODEXVERDE ?? "",
+  MASTODON_KEY_CONTRAPODER: process.env.MASTODON_KEY_CONTRAPODER ?? "",
   // MASTODON_KEY_COOPERATIVA: process.env.MASTODON_KET_COOPERATIVA ?? "",
   MASTODON_KEY_DF: process.env.MASTODON_KEY_DF ?? "",
   MASTODON_KEY_ELCIUDADANO: process.env.MASTODON_KEY_ELCIUDADANO ?? "",

+ 10 - 7
src/index.ts

@@ -5,6 +5,7 @@ import config from "./config";
 import { handler as chilecultura } from "./portales/chilecultura/handler";
 import { handler as ciper } from "./portales/ciper/handler";
 import { handler as codexverde } from "./portales/codexverde/handler";
+import { handler as contrapoder } from "./portales/contrapoder/handler";
 // import { handler as cooperativa } from "./portales/cooperativa/handler";
 import { handler as df } from "./portales/df/handler";
 import { handler as elciudadano } from "./portales/elciudadano/handler";
@@ -29,9 +30,9 @@ const context: Context = {
   awsRequestId: "",
   logGroupName: "",
   logStreamName: "",
-  done: () => {},
-  fail: () => {},
-  succeed: () => {},
+  done: () => { },
+  fail: () => { },
+  succeed: () => { },
   getRemainingTimeInMillis: () => 1
 };
 
@@ -39,6 +40,7 @@ const portalsHandlers = {
   "chilecultura": chilecultura,
   "ciper": ciper,
   "codexverde": codexverde,
+  "contrapoder": contrapoder,
   // "cooperativa": cooperativa,
   "df": df,
   "elciudadano": elciudadano,
@@ -52,17 +54,18 @@ const portalsHandlers = {
   "latercera": latercera,
   // "metrodesantiago": metrodesantiago,
   "tarreo": tarreo,
-  "theclinic": theclinic,
+  "theclinic": theclinic
 };
 
 const activePortalsHandlers: Array<Handler> = Object.keys(portalsHandlers)
-  .filter((portalName) => ! config.DEVELOP || config.DEV_ACTIVE_PORTALS.includes(portalName))
+  .filter((portalName) => !config.DEVELOP || config.DEV_ACTIVE_PORTALS.includes(portalName))
   .map((portalName) => portalsHandlers[portalName]);
 
 const cooldown = 10000; // 10 seconds
-async function main (): Promise<void> {
+async function main(): Promise<void> {
+  console.log(`${activePortalsHandlers}`)
   for (const portalHandler of activePortalsHandlers) {
-    await portalHandler(null, context, () => {});
+    await portalHandler(null, context, () => { });
     await new Promise((resolve) => setTimeout(resolve, cooldown));
   }
 }

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

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

+ 20 - 0
src/portales/contrapoder/handler.ts

@@ -0,0 +1,20 @@
+import { type Handler } from "aws-lambda";
+
+import config from "../../config";
+import Portal from "../portal";
+import ScraperMethods from "../../enums/scraper-methods";
+
+const name = `Contra Poder`;
+
+export const handler: Handler = new Portal(
+  name,
+  config.MASTODON_KEY_CONTRAPODER,
+  {
+    url: config.CONTRAPODER,
+    articlesSelector: "article",
+    titleSelector: "h2.fn__title",
+    linkSelector: "h2.fn_title a",
+    scraperMethod: ScraperMethods.AXIOS,
+    hashtags: ["Noticias", "ContraPoderChile"],
+  }
+).getHandler();