Merge pull request #6 from drguildo/feat/timeout

Add a configurable timeout
This commit is contained in:
Gabriel Ostrolucký 2019-06-15 19:59:15 +02:00 committed by GitHub
commit deddc564d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -2,10 +2,11 @@
#cfg #cfg
useragent="Love by u/gadelat" useragent="Love by u/gadelat"
timeout=60
subreddit=$1 subreddit=$1
url="https://www.reddit.com/r/$subreddit/.json?raw_json=1" url="https://www.reddit.com/r/$subreddit/.json?raw_json=1"
content=`wget -U "$useragent" -q -O - $url` content=`wget -T $timeout -U "$useragent" -q -O - $url`
mkdir -p $subreddit mkdir -p $subreddit
while : ; do while : ; do
urls=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")) | .data.preview.images[0].source.url') urls=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")) | .data.preview.images[0].source.url')
@ -19,7 +20,7 @@ while : ; do
ext=`echo -n "${url##*.}"|cut -d '?' -f 1` ext=`echo -n "${url##*.}"|cut -d '?' -f 1`
newname="$name"_"$subreddit"_$id.$ext newname="$name"_"$subreddit"_$id.$ext
echo $name echo $name
wget -U "$useragent" --no-check-certificate -nv -nc -P down -O "$subreddit/$newname" $url &>/dev/null & wget -T $timeout -U "$useragent" --no-check-certificate -nv -nc -P down -O "$subreddit/$newname" $url &>/dev/null &
a=$(($a+1)) a=$(($a+1))
done done
after=$(echo -n "$content"| jq -r '.data.after') after=$(echo -n "$content"| jq -r '.data.after')
@ -27,6 +28,6 @@ while : ; do
break break
fi fi
url="https://www.reddit.com/r/$subreddit/.json?count=200&after=$after&raw_json=1" url="https://www.reddit.com/r/$subreddit/.json?count=200&after=$after&raw_json=1"
content=`wget -U "$useragent" --no-check-certificate -q -O - $url` content=`wget -T $timeout -U "$useragent" --no-check-certificate -q -O - $url`
#echo -e "$urls" #echo -e "$urls"
done done