#!/usr/bin/perl use REST::Client; use DateTime; my $latitude = 30.29; my $longitude = -97.74; my $numDays = 6; # up to 7 days my $format = '12 hourly'; # '12 hourly' or '24 hourly' my $unit = 'e'; # 'e' for English; 'm' for metric my $XMLformat = 'DWML'; my $xml_file = '/Users/distler/Sites/weather/forecast.xml'; my $dt = DateTime->now; $dt->set_time_zone('local')->add( minutes => 2 ); # ensure the startDate is in the future my $startDate = $dt->strftime('%Y-%m-%d'); my $host = 'https://digital.weather.gov'; my $endpoint = '/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php'; my $weather = REST::Client->new({ host => $host }); my $query = $weather->buildQuery({ lat => $latitude, lon => $longitude, startDate => $startDate, numDays => $numDays, Unit => $unit, XMLformat => $XMLformat, format => $format }); $weather->GET("$endpoint?$query"); open(OUT, ">$xml_file"); print OUT $weather->responseContent();