mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-26 01:07:34 +00:00
yahoo picture search
This commit is contained in:
parent
a734b5f5ab
commit
e89942074a
@ -2,7 +2,7 @@
|
||||
# files: mycommands.sh.dist
|
||||
# copy to mycommands.sh and add all your commands and functions here ...
|
||||
#
|
||||
#### $$VERSION$$ v0.72-dev-6-ga51f8ca
|
||||
#### $$VERSION$$ v0.72-dev-7-ga734b5f
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
@ -65,10 +65,9 @@ else
|
||||
# Inline query examples
|
||||
# shellcheck disable=SC2128
|
||||
case "${iQUERY}" in
|
||||
"google "*) # search in google images
|
||||
"image "*) # search in yahoo images
|
||||
local search="${iQUERY#* }"
|
||||
answer_inline_multi "${iQUERY[ID]}" "$(my_image_search "${search}")"
|
||||
exit
|
||||
;;
|
||||
"photo") # manually provide URLs
|
||||
answer_inline_multi "${iQUERY[ID]}" "
|
||||
@ -97,18 +96,21 @@ exit
|
||||
answer_inline_query "${iQUERY[ID]}" "article" "GitHub" "http://github.com/topkecleon/telegram-bot-bash"
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
}
|
||||
|
||||
# place your processing functions here
|
||||
|
||||
# problem: google returns png :-(
|
||||
# $1 search parameter
|
||||
my_image_search(){
|
||||
local image result sep=""
|
||||
result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://www.google.com/search?q=$1&tbm=isch" | sed 's/</\n</g' | grep '<img')"
|
||||
local image result sep="" count="1"
|
||||
result="$(wget --user-agent 'Mozilla/5.0' -qO - "https://images.search.yahoo.com/search/images?p=$1" | sed 's/</\n</g' | grep "<img src=")"
|
||||
while read -r image; do
|
||||
image="${image#* src=\"}"; image="${image%%\" width=\"*}"
|
||||
[ "$count" -gt "9" ] && break
|
||||
image="${image#* src=\'}"; image="${image%%&pid=*}"
|
||||
[[ "${image}" = *"src="* ]] && continue
|
||||
echo "${sep}"; inline_query_compose "$RANDOM" "photo" "${image}"; sep=","
|
||||
count=$(( count + 1 ))
|
||||
done <<<"${result}"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user