-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseAds.ts
32 lines (21 loc) · 926 Bytes
/
parseAds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { FinnAd } from "./types.ts";
import { postToWebhook } from "./functions.ts";
import { readJSON, writeJSON } from "https://deno.land/x/[email protected]/mod.ts";
import * as R from "https://x.nest.land/[email protected]/mod.ts";
const WEEBHOOK = Deno.args[0];
const inputFile = Deno.args[1];
const outputFile = `filtered_${inputFile}`;
const inputData = await readJSON(inputFile);
const currData = await readJSON(outputFile);
const inputAds = inputData.docs;
const existingAds = currData.ads;
const adsByID = <T extends { ad_id: string }>(i: T): string => i.ad_id;
const foundAds = inputAds.map(adsByID);
const currentAds = existingAds.map(adsByID);
const difference = R.difference(foundAds, currentAds);
const newAds = inputAds.filter((i: FinnAd) => difference.includes(i.ad_id));
newAds.forEach((ad: FinnAd) => {
currData.ads.push(ad);
postToWebhook(ad, WEEBHOOK);
});
await writeJSON(outputFile, currData);