Last active
December 11, 2015 03:58
-
-
Save robtuley/4541752 to your computer and use it in GitHub Desktop.
PHP snippet to create a local river cache from the Rainchasers API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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