Landing : Athabascau University

Unit 7: Using External Data Sources

  • Public
By Mipam Lauder February 27, 2021 - 7:40pm

I wanted to provide my users with a live weather feed for the area that they wanted to travel to.  I was finally able to ( after many, many hours of things not working ) get the weather from Environment Canada when the user selected an area under the weather page.

I ran into too many issues to count, I really should have kept track of every issue, but I was pressed for time and trying to get the project finished.  The main issues I had related to CORS, the default security settings in browers when you try and fetch information from a site other than the one you're viewing.  After much reading, and experimenting, I finally realized that I wouldn't be able to get the weather with javascript alone, and that I would need to write a small php proxy to pass the data through from the webserver to the webpage.

I've written a bit of php in the past, so I was comfortable writing the php proxy.

Once I was able to fetch the weather, the second major issue I had was converting the xml file received into the weather data to be displayed.  I could not easily parse the xml file, and spent way too may hours trying to make it work.  In hindsite I should have given up on the xml approach, and tried to find another way to import and display the weather.

The website files are the same as those used for Unit 5:  Unit 5 website files