User Tools

Site Tools


Sidebar


Site Information


Interactive Maps

Sidebar

scode:perl:darksky

Darksky Weather

Get the weather. Sixty calls per minute free.
https://darksky.net

Returns are in JSON. Simple Perl processing (1st '#!' for XAMPP, 2nd for real systems - edit to match your environment):

#!perl
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use JSON;
 
### Locality ##
my $sLatLong = '42.3601,-71.0589';
 
### Vars ###
my $hpDecode;
my $sResults;
 
### Darksky ###
my $sDSkey = 'YourKeyGoesHere';
my $sDSurl = "https://api.darksky.net/forecast/$sDSkey/$sLatLong";
 
### Work ###
$sResults = get($sDSurl);
$hpDecode = decode_json($sResults);
 
print $hpDecode->{'currently'}->{'cloudCover'} . "\n";
print $hpDecode->{'hourly'}->{'summary'} . "\n";
print $hpDecode->{'daily'}->{'summary'} . "\n";
print $hpDecode->{'daily'}->{'data'}->[0]->{'summary'} . "\n";
 
print $hpDecode->{'daily'}->{'data'}->[0]->{'precipProbability'} . "\n";
print $hpDecode->{'daily'}->{'data'}->[0]->{'sunriseTime'} . "\n";
print $hpDecode->{'daily'}->{'data'}->[0]->{'sunsetTime'} . "\n";
 
print $hpDecode->{'daily'}->{'data'}->[0]->{'apparentTemperatureHigh'} . "\n";
print $hpDecode->{'daily'}->{'data'}->[0]->{'apparentTemperatureHighTime'} . "\n";
 
print $hpDecode->{'daily'}->{'data'}->[0]->{'apparentTemperatureLow'} . "\n";
print $hpDecode->{'daily'}->{'data'}->[0]->{'apparentTemperatureLowTime'} . "\n";
 
 
print "\n\nDone\n";

Output:

Mostly cloudy until this evening.
Snow (1–3 in.) on Saturday, with high temperatures rising to 37°F on Wednesday.
Mostly cloudy until evening.
0.05
1547124813
1547159048
17.4
1547157600
12.53
1547204400


Done
scode/perl/darksky.txt · Last modified: 2019/01/10 06:19 by terrill