Last active
June 24, 2017 19:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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