Skip to content

Instantly share code, notes, and snippets.

@angch
Created September 5, 2016 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angch/590eb5c12493838387ca01df05cd9f61 to your computer and use it in GitHub Desktop.
Save angch/590eb5c12493838387ca01df05cd9f61 to your computer and use it in GitHub Desktop.
Attempting to simply JSON extraction ala http://objectpath.org/ in Perl6.
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