Last active
February 25, 2021 17:18
-
-
Save jwittkoski/79f41db9c29f807a422af197a05ad2ae to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env perl | |
use v5.24; | |
use strict; | |
use warnings; | |
use utf8; | |
use XML::LibXML; | |
say "County"; | |
my $input_county = <STDIN>; | |
chomp $input_county; | |
say "City"; | |
my $input_city = <STDIN>; | |
chomp $input_city; | |
say "\n"; | |
my $source = "http://www.yr.no/place/Sweden/$input_county/$input_city/forecast.xml"; | |
my $dom = XML::LibXML->load_xml(location => $source); | |
binmode(STDOUT, ":utf8"); | |
foreach my $location ( $dom->findnodes('//weatherdata')) { | |
say "City: ", $location->findvalue('./location/name'); | |
say "Country: ", $location->findvalue('./location/country'); | |
say "\n"; | |
} | |
my $i = 1; | |
foreach my $info ( $dom->findnodes('//time') ) { | |
say 'Time ', $info->findvalue('@from'); | |
say "Temperature right now: ", $info->findvalue('./temperature/@value'), ' degrees celsius'; | |
last if ( $i == 1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment