Skip to content

Instantly share code, notes, and snippets.

@ghing
Last active June 24, 2017 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghing/0ac27e2413ed708e0e1cf4b22292e806 to your computer and use it in GitHub Desktop.
Save ghing/0ac27e2413ed708e0e1cf4b22292e806 to your computer and use it in GitHub Desktop.
Filter tweets stored by https://github.com/ghing/congressional-tweets to predefined list of screen names
#!/bin/bash
# Read one line of ndjson from stdin
read -r line
last_id_file=$1
if [ -z "$last_id_file" ]; then
last_id_file=.last-tweet-id
fi
if [ ! -f $last_id_file ]; then
echo $line | ndjson-map "d.id" | tr -d '"' > $last_id_file
fi
# Echo the line we read on to the next program
echo $lin
#!/bin/bash
last_id_file=.last-tweet-id
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-s|--sinceid)
since_id="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
# A since last tweet argument has not been specified as a command line
# argument. Try reading it from a dotfile.
if [ -z "$since_id" -a -f $last_id_file ]; then
read -r since_id<$last_id_file
fi
# If we got a tweet ID, either from a command line argument or a dotfile, pass
# it through to the search_tweets command.
since_id_args=""
if [ -n "$since_id" ]; then
since_id_args="--since-id $since_id"
fi
screen_name_args=""
for screen_name in $CONGRESSIONAL_SCREEN_NAMES; do
screen_name_args="$screen_name_args --screen-name $screen_name"
done
rm $last_id_file
eval congressional_tweets search_tweets "$since_id_args" "$screen_name_args" '"town hall"' |\
ndjson-map '{"screen_name": d.user.screen_name, "text": d.text, "id": d.id_str, "created_at": d.created_at, "url": "https://twitter.com/" + d.user.screen_name + "/status/" + d.id_str}' |\
while read -r line; do echo "$line" | ./capture_id.sh $last_id_file | jq; done
if [ ! -f $last_id_file ]; then
# No tweets since the last id specified. Save the previous last id to the
# dotfile.
echo "$since_id" > $last_id_file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment