Skip to content

Instantly share code, notes, and snippets.

@robtuley
Last active December 11, 2015 03:58
Show Gist options
  • Select an option

  • Save robtuley/4541752 to your computer and use it in GitHub Desktop.

Select an option

Save robtuley/4541752 to your computer and use it in GitHub Desktop.
PHP snippet to create a local river cache from the Rainchasers API.
<?php
$rivers = array();
$next = 'http://api.rainchasers.com/v1/river';
while ($next) {
$chunk = json_decode(file_get_contents($next),true);
if (!$chunk || $chunk['status']!=200) exit("resync fail at $next");
$rivers = array_merge($rivers,$chunk['data']);
fwrite(STDOUT,'.');
$requests[] = $next = isset($chunk['meta']['link']['next']) ? $chunk['meta']['link']['next'] : false;
}
fwrite(STDOUT,' retrieved '.count($rivers)." rivers\nresume from {$chunk['meta']['link']['resume']}\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment