Last active
May 28, 2020 14:13
-
-
Save morkin1792/91f674a9df7052324d4c9f71cf59e30a to your computer and use it in GitHub Desktop.
Um script para alertar quando o preco de um produto ficar ao menor ou igual a um determinado valor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
start=$(date +%s) | |
link="$1" | |
price="$2" | |
command="$3" | |
function end() { | |
echo -e '\nBoas compras...\nRodou por '$(($(date +%s)-start))' segundos' | |
exit 0 | |
} | |
trap end EXIT | |
if [ "$1" = "-h" ] || [ -z "$1" ] || [ ! "$#" -eq 3 ]; then | |
echo -e '\nUm script para executar um comando, quando o preco de um produto ficar menor ou igual a um determinado valor.\n\n USO: '$0' LINK PRECO COMANDO\n\nExemplo:\n '$0' "https://www.zoom.com.br/notebook/notebook-acer-a515-51g-58vh-intel-core-i5-7200u-15-6-8gb-hd-1-tb-geforce-940mx" 2000 "vlc /home/w/sounds/vuvuzela.mp3"\n' | |
exit 0 | |
fi | |
clear && sleep 0.2 | |
while [ true ]; do | |
html="$(curl -sL $link)" | |
if echo "$link" | grep -q 'zoom.com.br'; then | |
p=$(echo "$html" | sed 's/.*<strong>\([^<]*\)<span.*/ \1/' | awk '{print $2}' | sed 's/[.]//' | tail -1) | |
nome=$(echo "$html" | grep -Eoi '","name": "[^"]+"' | sed 's/.$//' | sed 's/^.\{11\}//' | head -1) | |
elif echo "$link" | grep -q 'kabum.com.br'; then | |
p=$(echo "$html" | grep '<meta itemprop="price" content="' | grep -oE '[0-9]+' | head -1) | |
nome=$(echo "$html" | grep "<a href='https://api.whatsapp.com/send?text=" | grep -Eo 'text=[^/]+' | sed 's/.\{8\}$//' | sed 's/^.\{5\}//') | |
else | |
echo 'Esse site ainda não é suportado... :(' | |
exit 0 | |
fi | |
re='^[0-9]+$' | |
if [[ ! $p =~ $re ]]; then | |
echo '[-] Erro em '$link | |
sleep $(($RANDOM%10+125)) | |
continue | |
fi | |
if (($p <= $price)); then | |
echo "OPA! Confere o preço aí: $p - $link" | |
notify-send -a OPAAAAAAA -i firefox "PRECO DE $p CONFERE AI" -t 10000 | |
echo $'\a' | |
amixer set Master 100% 2>/dev/null >&2 #tentando aumentar volume | |
speaker-test -t wav -p 1 2>/dev/null >&2 & sleep 10 && pkill 'speaker-test' 2>/dev/null | |
eval "$command" & | |
xdg-open "$link" | |
exit 0 | |
else | |
pre=$(date +[%H:%M:%S@%d' '%h]) | |
echo "$pre Meta: $price, Preco Atual: $p, Produto: $nome" | |
fi | |
sleep $(($RANDOM%10+25)) | |
done | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local="$(cd "$(dirname "$0")";pwd)" | |
pids=() | |
function ctrl_c() { | |
kill ${pids[*]} | |
exit 0 | |
} | |
trap ctrl_c SIGINT | |
while read line ; do | |
if [ -z "$line" ]; then | |
continue | |
fi | |
price=$(echo $line | awk '{print$1}') | |
link=$(echo $line | awk '{print$2}') | |
bash "$local"/core.sh "$link" $price "echo gogogo" & | |
pid=$! | |
pids+=($pid) | |
done < "$local/urls.txt" | |
while read; do echo -n; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2000 https://www.kabum.com.br/produto/100235/placa-de-video-galax-nvidia-geforce-rtx-2060-6gb- | |
100 https://www.zoom.com.br/fone-de-ouvido-e-headset/fone-de-ouvido-bluetooth-xiaomi-redmi-airdots |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment