1 # This code is mostly the work of Lucien Dunning (ldunning@gmail.com). It was
2 # used to provide search functionality for the Environment Canada weather
5 package ENVCANLocation;
10 our @ISA = qw(Exporter);
11 our @EXPORT = qw(doSearch AddStationIdSearch AddRegionIdSearch AddCitySearch AddProvinceSearch);
15 my @stationidsearches;
23 my $parser = new XML::Parser( Style => 'Stream' );
24 open(XML, 'ENVCAN-Stations.xml') or die "cannot open file\n";
27 return $searchresults;
38 my ($expat, $name, %atts) = @_;
40 if ($name eq 'station') {
41 $expat->{CurrEntry} = {};
42 $expat->{MatchFound} = 0;
49 my $text = $expat->{Text};
52 if ($expat->in_element('station_id')) {
53 $expat->{CurrEntry}->{station_id} = $text;
54 if (!$expat->{MatchFound}) {
55 foreach $search (@stationidsearches) {
56 if ($text =~ m/$search/i) {
57 $expat->{MatchFound} = 1;
64 if ($expat->in_element('region_id')) {
65 $expat->{CurrEntry}->{region_id} = $text;
66 if (!$expat->{MatchFound}) {
67 foreach $search (@regionidsearches) {
68 if ($text =~ m/$search/i) {
69 $expat->{MatchFound} = 1;
76 if ($expat->in_element('province')) {
77 $expat->{CurrEntry}->{province} = $text;
78 if (!$expat->{MatchFound}) {
79 foreach $search (@provincesearches) {
80 if ($text =~ m/$search/i) {
81 $expat->{MatchFound} = 1;
88 if ($expat->in_element('city')) {
89 $expat->{CurrEntry}->{city} = $text;
90 if (!$expat->{MatchFound}) {
91 foreach $search (@citysearches) {
92 if ($text =~ m/$search/i) {
93 $expat->{MatchFound} = 1;
102 my ($expat, $name) = @_;
104 if ($name eq 'station' && $expat->{MatchFound}) {
105 push (@$searchresults, $expat->{CurrEntry});
106 if ($expat->{finish}) {
116 push (@citysearches, $city);
119 sub AddProvinceSearch {
120 my $province = shift;
121 push (@provincesearches, $province);
124 sub AddStationIdSearch {
125 my $station_id = shift;
126 push (@stationidsearches, $station_id);
129 sub AddRegionIdSearch {
130 my $region_id = shift;
131 push (@regionidsearches, $region_id);