Bug fixes for 4c function

This commit is contained in:
Michael De Roover 2022-04-06 02:44:08 +02:00
parent 6a560e460a
commit ad60da95f2
Signed by: vim
GPG Key ID: 075496E232CE04CB

View File

@ -256,16 +256,18 @@ konachan(){
4c(){ 4c(){
args args
tmp="/tmp/4chan" tmp="/tmp/4chan"
json="$tmp/${args[0]}.json" threads="$tmp/${args[0]}.json"
[ ! -d $tmp ] && mkdir $tmp [ ! -d $tmp ] && mkdir $tmp
[ $(find $json -mmin +60) ] && rm $json [ $(find $threads -mmin +60) ] && rm $threads
[ ! -f $json ] && wget -O $json https://a.4cdn.org/${args[0]}/threads.json [ ! -f $threads ] && wget -O $threads https://a.4cdn.org/${args[0]}/threads.json
thread=$(jq -r '.[].threads[].no' < $json | shuf | head -n1) thread=$(jq -r '.[].threads[].no' < $threads | shuf | head -n1)
img=$(curl -s https://a.4cdn.org/${args[0]}/thread/$thread.json | jq -r '.posts[].tim' | shuf | head -n1) posts=$(curl -s https://a.4cdn.org/${args[0]}/thread/$thread.json)
url="https://i.4cdn.org/${args[0]}/$img" imgs=$(jq -r ".posts[] | select(.ext==\".jpg\"), select(.ext==\".png\")" <<< $posts)
# TODO: Try to determine from JSON output whether image is PNG or JPG. no=$(jq -r ".no" <<< $imgs | shuf | head -n1)
sendpic "$url.jpg" img=$(jq -r "select(.no==$no) | .tim" <<< $imgs)
sendpic "$url.png" ext=$(jq -r "select(.no==$no) | .ext" <<< $imgs)
url="https://i.4cdn.org/${args[0]}/${img}${ext}"
sendpic "$url" "<a href=\"$url\">sauce</a>"
} }
lfy(){ lfy(){