From b04cdbe8ec53248f250c5902094f164b619872b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Sun, 11 Jul 2021 16:27:17 +0200 Subject: [PATCH] create more tools to make my life easier --- bin/extract-unique-pages-from-event-nodes | 16 +++++++++++++ bin/filter-by-ids | 28 +++++++++++++++++++++++ bin/orland-pages-from-event-nodes | 7 ++++++ bin/remove-profile-picture | 23 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100755 bin/extract-unique-pages-from-event-nodes create mode 100755 bin/filter-by-ids create mode 100755 bin/orland-pages-from-event-nodes create mode 100755 bin/remove-profile-picture diff --git a/bin/extract-unique-pages-from-event-nodes b/bin/extract-unique-pages-from-event-nodes new file mode 100755 index 0000000..c51427c --- /dev/null +++ b/bin/extract-unique-pages-from-event-nodes @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +PATH="$PATH:$HOME/src/garbit/lib/facebook-event-scraper/bin" + +if [ "$1" == "" ]; then + echo "This script takes in an path to an JSON file containing an Array."; + exit 0; +fi + +cat $1 \ + | get-hosts-from-event-nodes \ + | flatten-array \ + | get-pages-from-hosts \ + | unique-by-id \ + | remove-profile-picture + diff --git a/bin/filter-by-ids b/bin/filter-by-ids new file mode 100755 index 0000000..a5af015 --- /dev/null +++ b/bin/filter-by-ids @@ -0,0 +1,28 @@ +#!/usr/bin/env node +const pathOr = require('ramda/src/pathOr'); +let input = []; + +// YOLO +let ids = eval(process.argv.slice(2).pop()).map((id) => `${id}`); + +process.stdin.resume(); +process.stdin.setEncoding('utf8'); + +process.stdin.on('data', (data) => { + input.push(data); +}); + +process.stdin.on('end', () => { + const str = input.join(''); + const arr = JSON.parse(str); + + const output = arr.reduce((acc, elem) => { + if (ids.includes(elem.id)) { + return acc; + } else { + return [...acc, elem]; + } + }, []); + + console.log(JSON.stringify(output)); +}); diff --git a/bin/orland-pages-from-event-nodes b/bin/orland-pages-from-event-nodes new file mode 100755 index 0000000..e00d4fb --- /dev/null +++ b/bin/orland-pages-from-event-nodes @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +PATH="$PATH:$HOME/src/garbit/lib/facebook-event-scraper/bin" + +extract-unique-pages-from-event-nodes "$1" \ + | filter-by-ids \ + "[119117068112852,170097818488]" diff --git a/bin/remove-profile-picture b/bin/remove-profile-picture new file mode 100755 index 0000000..f4a4911 --- /dev/null +++ b/bin/remove-profile-picture @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +const pathOr = require('ramda/src/pathOr'); + +let input = []; + +process.stdin.resume(); +process.stdin.setEncoding('utf8'); + +process.stdin.on('data', (data) => { + input.push(data); +}); + +process.stdin.on('end', () => { + const str = input.join(''); + const events = JSON.parse(str); + + let uniquePages = []; + + console.log( + JSON.stringify(events.map(({ profilePicture, ...event }) => event)), + ); +});