aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-011/feng-chang/perl5/ch-3.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-011/feng-chang/perl5/ch-3.pl b/challenge-011/feng-chang/perl5/ch-3.pl
new file mode 100755
index 0000000000..469483b200
--- /dev/null
+++ b/challenge-011/feng-chang/perl5/ch-3.pl
@@ -0,0 +1,26 @@
+#!/bin/env perl
+
+use Modern::Perl;
+use WWW::Mechanize;
+use JSON;
+use Data::Dumper;
+use Getopt::Long;
+
+my $base_url = 'http://api.openweathermap.org/data/2.5/weather';
+my $app_id = 'appid=82642c9af842d8d57f7df99b291e0e75';
+
+my $city = 'london';
+my $country = '';
+
+GetOptions(
+ 'city=s' => \$city,
+ 'country=s' => \$country,
+);
+
+my $m = WWW::Mechanize->new() or die "cannot initialize robot\n";
+
+my $url = "$base_url?q=$city";
+$url .= ",$country" if $country;
+$url .= "&$app_id";
+
+print Dumper(decode_json($m->content)) if $m->get($url);