#!/usr/bin/perl -w
use LWP::Simple;
use Fcntl qw(:DEFAULT :flock);
my $interval = 60; # seconds between calls
my $url='http://www.cryptonator.com/api/ticker/btc-gbp';
my $gpdata;
$SIG{TERM}=sub{close(PIPE);if(defined(*OUT)){close(OUT);print "done\n"
+;exit;}};
sub init{
local $/=undef;
$gpdata=<DATA>;
open PIPE, "|gnuplot -persist -geometry 512x384+0+0" || die "Can't
+ initialize gnuplot\n";
select((select(PIPE), $| = 1)[0]);
}
sub fetch{
my $replie = get($url);
print"$replie \n";
my($a,$b,$c,$d)= $replie =~ /^.+?(\d+\.\d+).+?(\d+\.*\d*).+?(\d+\
+.\d+).+?(\d+).*$/;
$a="not defined" unless defined($a);
$b="not defined" unless defined($b);
$c="not defined" unless defined($c);
$d="not defined" unless defined($d);
open(OUT,">>","/home/philip/Desktop/PERLBITCOIN/TICKER/bitgbpZ.dat
+") or die "BIT File open error $!\n";
print OUT "$d,$a,$c,$b\n";
close(OUT);
}
sub update{
print PIPE $gpdata;
}
sub loop{
fetch();
sleep 1;
update();
}
sub main{
init();
do{
loop;
sleep 60;
}while(1)
}
main;
__DATA__
reset
set terminal 'wxt'
delta_v(x) = ( vD = x - old_v, old_v = x, vD)
old_v = NaN
unset key
set xtics border in scale 0,0 nomirror rotate by -90 offset character
+ 0,0 autojustify
set datafile separator ','
set bmargin at screen 0.2
set palette defined (-1 "red", 1 "#1B6821")
set cbrange [-1:1]
set grid
set yrange [*:*]
unset colorbox
set style fill solid noborder
#set xrange [1446160802-946684800:1446160902-946684800]
set xdata time
set timefmt "%s"
set xtics 60
set format x "%H:%M:%S" # or whatever
set xlabel "time"
#set xtics autofreq
data=system("tail -n 1 /home/philip/Desktop/PERLBITCOIN/TICKER/bitgbpZ
+.dat | cut -d ',' -f2")
set title data
plot '< tail -n 60 /home/philip/Desktop/PERLBITCOIN/TICKER/bitgbpZ.dat
+' using 1:($2):((delta_v($2) > 0.0) ? 1 : -1 ) title data with lines
+p lt 6 lw 2 palette
Thanks to all for help and suggestions |