From bffad0b703f014fc9ab4cda98f74d4c4ac11c866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Wed, 20 May 2020 01:30:24 +0200 Subject: [PATCH] add usage and arg parsing --- scrape.sh | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/scrape.sh b/scrape.sh index c0edab9..4cbde4c 100755 --- a/scrape.sh +++ b/scrape.sh @@ -1,7 +1,93 @@ -#!/bin/sh +#!/bin/bash -if ! [ -d node_modules ]; then - yarn -fi +readonly ARGS="$@" -exec node scrape.js +function usage { + cat <<- EOF + ./scrape.sh [options] + + Scrape facebook event pages. + + This script will always return an JSON array. + + OPTIONS: + -e --event Facebook event id. Scrape a single Facebook + event. + -p --page Facebook page id. Scrape all events of a + specific facebook page. + -a --pages Array of Facebook page ids. This is a space + seperated list of page ids. + -h --help -? print usage + + EXAMPLES: + Scrape events of a facebook page with id 133713371337 + ./scrape.sh --page 133713371337 + ./scrape.sh -p 133713371337 + + Scrape a facebook event with id 420420420420 + ./scrape.sh --event 420420420420 + ./scrape.sh -e 420420420420 + + Scrape a facebook event with id 123 and all events from page 1323 + ./scrape.sh --event 123 --page 1323 +EOF +} + +function parse_args { + if [ "$1" = "" ]; then + echo "" + fi + + while [[ $# -gt 0 ]]; do + key="$1" + case $key in + -e|--event) + shift + local event_id; + event_id=$1 + ;; + -p|--page) + ;; + -a|--pages) + ;; + *) + usage + exit 1 + ;; + esac + shift + done +} + +function install_node_dependencies { + if ! [ -d node_modules ]; then + yarn + fi +} + +function check_dependencies { + local missing; + missing=false; + + if [ ! $(command -v node) ]; then + echo "Dependency missing. Please install node.js and make it available to the path as 'node'." + missing=true + fi + + if [ ! $(command -v yarn) ]; then + echo "Dependency missing. Please install yarn and make it available to the path as 'yarn'." + missing=true + fi + + install_node_dependencies + + if [ "${missing}" != "false" ]; then + exit 1; + fi + + return 0; +} + +check_dependencies \ + && parse_args "${ARGS}" \ + && scrape