#!/bin/bash readonly ARGS="$@" 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