Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
# args
NAME=$1 # screen name
MARGIN=${2:-1200} # text tweets which is older by this margin time will be removed (default: 20 min = 1200 sec)
INTERVAL=${3:-600} # io-loop interval
echo "NAME=${NAME}"
echo "MARGIN=${MARGIN}"
echo "INTERVAL=${INTERVAL}"
# helpers
tw-cd() {
twurl set default "$1"
}
tw-timeline() {
tw-cd "$NAME"
twurl "/1.1/statuses/user_timeline.json?count=200&screen_name=$NAME"
}
tw-rm() {
tw-cd "$NAME"
twurl -XPOST "/1.1/statuses/destroy/$1.json" >/dev/null
}
# io-loop
while :; do
echo "Checking..."
cur=$(date +%s)
s=$((cur - MARGIN))
tw-timeline |
jq -r '.[] | if (.extended_entities.media | length) == 0 then
"echo $(date -d \"\(.created_at)\" +%s) \(.id_str)"
else
empty
end' | sh |
while read t id; do
if [ "$t" -lt "$s" ]; then
echo "rm $id"
tw-rm "$id"
fi
done
echo "...Done"
sleep "${INTERVAL}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment