Commit 1f2478e6 by Joe Holden

only redraw if the feed has been updated, add optional argument for number of cars to print

parent facbfbb9
......@@ -8,23 +8,13 @@ $url = 'http://www.nascar.com/live/feeds/live-feed.json';
$duration = new Khill\Duration\Duration;
$climate = new League\CLImate\CLImate;
// fetch json
$json = json_decode(file_get_contents($url));
if (json_last_error()) {
printf("=> %s, %s: %s\n", 'json decode error', json_last_error(), json_last_error_msg());
exit;
}
while(true) {
if (isset($json))
$old = $json;
// parse document
$json = json_decode(file_get_contents($url));
file_put_contents('live-feed.json', json_encode($json, JSON_PRETTY_PRINT));
$count = 1;
while(true) {
$old = $json;
if ($count == 3) {
$json = json_decode(file_get_contents($url));
file_put_contents('live-feed.json', json_encode($json, JSON_PRETTY_PRINT));
$count = 1;
}
if (json_last_error()) {
printf("=> %s, %s: %s\n", 'json decode error', json_last_error(), json_last_error_msg());
} else {
......@@ -32,10 +22,10 @@ while(true) {
$climate->clear();
$climate->out("No race currently running.");
}
draw($json, $old, $climate, $duration, $count);
if ($json->time_of_day > $old->time_of_day)
draw($json, $old, $climate, $duration, $count);
}
sleep(1);
$count++;
}
function draw($json, $old, $climate, $duration, $refresh) {
......@@ -132,7 +122,7 @@ function draw($json, $old, $climate, $duration, $refresh) {
$outcount = 0;
$climate->white()->inline($series . ': ');
$climate->lightBlue()->inline(sprintf("%s @ %s ", $json->run_name, trim($json->track_name)));
$climate->lightBlue()->inline(sprintf("%s @ %s", $json->run_name, trim($json->track_name)));
$climate->white()->inline(", track length: ");
$climate->lightGray()->inline($json->track_length . ' m');
$climate->white()->inline(", race length: ");
......@@ -158,6 +148,8 @@ function draw($json, $old, $climate, $duration, $refresh) {
$climate->out('On track (' . $ontrack . '):');
$car = 1;
if (isset($GLOBALS['argv'][1]))
$carcount = $GLOBALS['argv'][1];
while ($car <= $carcount) {
if (isset($table[$car])) {
$entry = $table[$car];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment