Files
greptweet/expand-urls.sh
Kai Hendry 782a06d13f Avoid httpd killing fetchtweets early by executing it off in the background
TODO: some UI if lock is around, to tell folks a fetch is underway
2012-07-24 17:23:31 +02:00

20 lines
428 B
Bash
Executable File

#!/usr/bin/env bash
# vim: set ts=4 sw=4
test -s "$1" || exit
test "${1##*.}" = 'txt' || exit
temp=$(mktemp "$1.XXXX")
trap "rm -f $temp" EXIT
IFS='|'
while read -r id date text
do
url=$(echo $text | grep --only-matching --perl-regexp "http(s?):\/\/[^ \"\(\)\<\>]*")
expandedURL=$(curl "$url" -m5 -s -L -I -o /dev/null -w '%{url_effective}')
t=${text/$url/$expandedURL}
echo "$id|$date|$t"
done < $1 > $temp
mv $temp $1