Skip to content

Instantly share code, notes, and snippets.

@fabioadrianosoares
Created July 23, 2015 14:38
Show Gist options
  • Save fabioadrianosoares/82a91f58fa2fa12e09c5 to your computer and use it in GitHub Desktop.
Save fabioadrianosoares/82a91f58fa2fa12e09c5 to your computer and use it in GitHub Desktop.
Tracking de pedidos na directlog
*/5 * * * * /home/ZZZZZ/track-directlog/tracking-directlog.sh 99999999 8888888 Produto > /dev/null 2>&1
onde http://www.directlog.com.br/tracking/index.asp?tipo=2&valor=99999999&cod=8888888
use warnings;
use strict;
my $saida = '';
my $status = 0;
while (<>)
{
if (/^<tr style="font-/)
{
print "$saida\n" if ($saida ne '');
$saida = '';
$status = 1;
}
if ($status == 1)
{
if (/^<b>([^<]+)/)
{
$saida .= ($saida eq '' ? '' : ' - ') . $1;
}
}
}
print "$saida\n" if ($saida ne '');
#! /bin/bash
function avisar {
MENSAGEM=$1;
echo $MENSAGEM;
wget -q -O /dev/null --header='Authorization: Bearer YYYYYYYY' \
--header='Content-Type: application/json' \
--post-data="{\"device_iden\": \"XXXXXXXXXXXX\", \"type\": \"note\", \"title\": \"Tracking de pedido\", \"body\": \"$MENSAGEM\"}" \
https://api.pushbullet.com/v2/pushes;
}
STATUS=$(wget -q -O - http://www.directlog.com.br/tracking/index.asp?tipo=2\&valor=$1\&cod=$2 | perl /home/ZZZZZ/track-directlog/parser.pl | tail -1);
if [ -z "$STATUS" ] ; then
exit 1;
fi
ARQUIVO_STATUS=/home/ZZZZZ/track-directlog/STATUS_$1_$2.txt;
STATUS_MD5=$(echo -n $STATUS | md5sum);
STATUS_ANTERIOR=$(cat $ARQUIVO_STATUS 2> /dev/null);
if [ "$STATUS_ANTERIOR" != "$STATUS_MD5" ] ; then
avisar "$3 - $STATUS";
echo -n $STATUS | md5sum > $ARQUIVO_STATUS;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment