You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

112 lines
2.3 KiB

#!/bin/bash
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.
-h --help -? print usage
--events List of Facebook event ids. See examples for
format.
-p --page Facebook page id. Scrape all events of a
specific facebook page.
--pages List of Facebook page ids. See examples for
format.
NOTE:
Events and pages needs to be public. Private events or pages are not yet
supported.
EXAMPLES:
EOF
}
event_ids="";
pages_ids="";
function scrape_event {
local event_id;
event_id="$1"
if [ "" == "${event_ids}" ]; then
event_ids="${event_id}"
else
event_ids="${event_ids},${event_id}"
fi
}
function scrape_page {
local page_id;
page_id="$1"
if [ "" == "${pages_ids}" ]; then
pages_ids="${page_id}"
else
pages_ids="${pages_ids},${page_id}"
fi
}
function parse_args {
if [ "$1" = "" ]; then
echo ""
fi
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-e|--event|--events)
shift
scrape_event "$1"
;;
-p|--page|--pages)
shift
scrape_page "$1"
;;
*)
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;
}
function scrape {
exec node scrape.js --event_ids="${event_ids}" --page_ids="${pages_ids}"
}
check_dependencies \
&& parse_args "$@" \
&& scrape