Created
September 5, 2016 12:01
-
-
Save angch/590eb5c12493838387ca01df05cd9f61 to your computer and use it in GitHub Desktop.
Attempting to simply JSON extraction ala http://objectpath.org/ in Perl6.
This file contains 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
use v6; | |
use Net::HTTP::GET; | |
use JSON::Fast; | |
my $appid = %*ENV{'APPID'} or die "Need APPID in env var from openweathermap.org"; | |
my $contents; | |
if (1) { | |
my $response = Net::HTTP::GET("http://api.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&cluster=yes&appid=" ~ $appid); | |
$contents = $response.content; | |
} else { | |
$contents = slurp "weather.txt"; # cached. | |
} | |
say (from-json($contents){'list'} | |
.grep: { $_{'main'}{'temp'} > 20 && $_{'clouds'}{'all'} == 0 } | |
).map: {$_{'name'} }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment