Browse Source

update scrape script to accpect args

fix-broken-scrape
Jørgen Lien Sellæg 6 years ago
parent
commit
ef763d6768
  1. 61
      scrape.sh

61
scrape.sh

@ -1,7 +1,5 @@
#!/bin/bash
readonly ARGS="$@"
function usage {
cat <<- EOF
./scrape.sh [options]
@ -13,24 +11,42 @@ function usage {
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.
-a --pages Array of Facebook page ids. This is a space
seperated list of page ids.
-h --help -? print usage
--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:
Scrape events of a facebook page with id 133713371337
./scrape.sh --page 133713371337
./scrape.sh -p 133713371337
EOF
}
Scrape a facebook event with id 420420420420
./scrape.sh --event 420420420420
./scrape.sh -e 420420420420
event_ids="";
pages_ids="";
Scrape a facebook event with id 123 and all events from page 1323
./scrape.sh --event 123 --page 1323
EOF
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 {
@ -41,14 +57,13 @@ function parse_args {
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-e|--event)
-e|--event|--events)
shift
local event_id;
event_id=$1
scrape_event "$1"
;;
-p|--page)
;;
-a|--pages)
-p|--page|--pages)
shift
scrape_page "$1"
;;
*)
usage
@ -88,6 +103,10 @@ function check_dependencies {
return 0;
}
function scrape {
exec node scrape.js --event_ids="${event_ids}" --page_ids="${page_ids}"
}
check_dependencies \
&& parse_args "${ARGS}" \
&& parse_args "$@" \
&& scrape

Loading…
Cancel
Save