Skip to content

perltaiwan/Weather-TW

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Weather::TW - Fetch Taiwan weather data from http://www.cwb.gov.tw/ Most methods are reimplimented in Weather::TW::Forecast use them instead.

SYNOPSIS

use Weather::TW::Forecast;
my $weather = Weather::TW::Forecast->new(
  location => '台北',
);
foreach ($weather->short_forecasts){
  say $_->start;
  say $_->end;         # DateTime objects specify forecast time interval
  say $_->temperature; # Temperature string, ex: '23 ~ 25'
  say $_->weather;     # Weather string, ex "陰短暫陣雨" 
  say $_->confortable; # ex '舒適'
  say $_->rain;        # probabilty to rain, 0~100%
}
foreach ($weather->weekly_forecasts){
  say $_->day;         # DateTime object
  say $_->temperature; # Temperature string, ex: '23 ~ 25'
  say $_->weather;     # Weather string, ex "陰短暫陣雨" 
}
my $hash_ref = $weather->montly_mean;
say $hash_ref->{temp_high}; # Maximum temperature
say $hash_ref->{temp_low};  # Mininum temperature
say $hash_ref->{rain};      # Rain precipitation (mm)

DESCRIPTION

Weather::TW::Forecast reimplement Weather::TW with new web address (from V6 to V7) and new parser (use Mojo::DOM instead of HTML::TreeBulder). The methods in Weather::TW will be deprecated and shiped to Weather::TW::Forecast. More submodules will be develop to handle obsevations and detail rain infos. Weather::TW will be a abstract class to access these submodules.

OLD SYNOPSIS

Documentation below will be deprecated.

  use Weather::TW;


  my $weather = Weather::TW->new;
  my $xml = $weather->area('Taipei City')->xml;
  my $json = $weather->json;
  my $yaml = $weather->yaml;
  my %hash = $weather->hash;


  foreach my $area ($weather->area_en){
    my $xml = $weather->area($area)->xml
    print $xml;
  }


use utf8;
$xml = $weather->area('台北')->xml;
# Chinese also works!

DESCRIPTION

This module parse data from http://www.cwb.gov.tw/ (中央氣象局), and generates xml/json/hash/yaml data.

OLD METHODS

  • new

Create a new Weather::TW object. Available option is lang, see method lang.

$weather = Weather::TW->new( lang => 'zh' );
  • area($area_name)

City name can be either Chinese or English. The returned value is $self so you can use it for cascading.

$xmlstr = $weather->area('Taipei City')->xml;

The available area names are:

台北市         Taipei City
新北市         New Taipei City
台中市         Taichung City
台南市         Tainan City
高雄市         Kaohsiung City
基隆北海岸     Keelung North Coast
桃園           Taoyuan
新竹           Hsinchu
苗栗           Miaoli
彰化           Changhua
南投           Nantou
雲林           Yunlin
嘉義           Chiayi
屏東           Pingtung
恆春半島       Hengchun Peninsula
宜蘭           Yilan
花蓮           Hualien
台東           Taitung
澎湖           Penghu
金門           Kinmen
馬祖           Matsu
  • lang($lang)

Available options are 'zh' or 'en'.

  • area_zh

Return area names in Chinese.

@names = $weather->area_zh;
  • area_en

Return area names in English.

@names = $weather->area_en;
  • xml

Return data as xml.

  • json

Return data as json.

  • json_pretty

Pretty json.

  • yaml

Return data as yaml.

  • hash

Return a perl hash object.

%hash = $weather->hash;

SEE ALSO

https://github.com/dryman/Weather-TW

and

XML::Smart

AUTHOR

dryman, idryman@gmail.com

COPYRIGHT AND LICENSE

Copyright (C) 2011 by dryman

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.

About

A perl module to parse weather data from http://www.cwb.gov.tw

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages