#!/usr/bin/perl -w my $pid; $pid = fork; if($pid == 0) { my $pid1 = open(CHILD, "|-", "gnuplot -persist ") or die "Couldn't fork: $!\n"; local $/=undef; my $plot=; print CHILD "$plot\n"; close(CHILD); print"forking\n"; exit; } use LWP::Simple; use Fcntl qw(:DEFAULT :flock); $|++; $SIG{TERM}=sub{print "ok1\n";alarm(0);exit;}; my $url='https://www.cryptonator.com/api/ticker/btc-gbp'; print"ok2\n"; my $interval = 30; # seconds between calls fetch(); sub fetch{ print"ok3\n"; 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/bitgbp1.dat") or die "BIT File open error $!\n"; unless (flock(OUT, LOCK_EX|LOCK_NB)) { warn "can't immediately write-lock the file ($!), blocking ..."; unless (flock(OUT, LOCK_EX)) { die "can't get write-lock on numfile: $!"; } } print OUT "$c,$a,$d\n"; flock(OUT, LOCK_UN) or die "cant unlock file\n"; close(OUT); #print "$c,$a,$d\n"; alarm($interval); }; $SIG{ALRM}=\&fetch; 1 while 1; __DATA__ reset 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.15 #set palette defined (100 "red", 200 "green", 300 "blue") set palette defined (-1 "red", 1 "#1B6821") #set palette model RGB defined ( -1 'red', 1 '#006400', 0 'black' ) set cbrange [-1:1] set grid set yrange [*:*] unset colorbox set style fill solid noborder #set xrange [1446061653-946684800:1446064653-946684800] set xdata time set timefmt "%s" set format x "%H:%M" # or anything else set xlabel "time" set xtics autofreq data=system("tail -n 1 '/home/philip/Desktop/PERLBITCOIN/TICKER/bitgbp1.dat' | awk '{print $0}'") print delta_v(2) plot '< tail -n 40 /home/philip/Desktop/PERLBITCOIN/TICKER/bitgbp1.dat' using 3:2:((delta_v($2) > 0.0) ? 1 : -1 )with impulses lw 2 palette pause 10 reread replot;