Simple private API to get current weather information at a lon/lat position from Environment Canada (EC).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

2 years ago
  1. (status: alpha/brain-dump)
  2. # Weather
  3. Simple private API to get current weather information at a lon/lat position
  4. from Environment Canada (EC).
  5. ## Requirements
  6. * webserver (tested with nginx and php-fpm)
  7. * php7 (tested with PHP 7.2)
  8. * php7-simplexml
  9. * composer
  10. * postgresql (tested with 11.3)
  11. * postgis (postgresql extension)
  12. ## How does it work
  13. The list of weather stations[1] published by Environment Canada and their
  14. lat/lon locations[2] are imported into the database.
  15. When we pass a lat/lon pair to our API, we use PostGIS to find the closest
  16. weather station, and then query the proper EC endpoint to get current
  17. weather[2] from that weather station.
  18. [1] http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/siteList.xml
  19. [2] example: http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/BC/s0000671_e.xml
  20. ## Configure
  21. * Run `composer install` in the "private" folder
  22. * Copy "config.dist.php" to "config.php" and edit the values
  23. If you want to bootstrap the database with the weather station information, use
  24. `pg_restore` with the dump provided in "private/weather.sql.dump"
  25. If you want to import the weather station data yourself:
  26. * Create a new database
  27. * Enable the postgis features on it
  28. * Run the "create_table.php" script in "private/src/scripts"
  29. * Run the "import_sites.php" script in "private/src/scripts" (this takes a while)
  30. ## Request
  31. `curl -H "secret: xxx" https://example.org?lat=45.00&lon=-75.00`
  32. ## Response
  33. ```
  34. {
  35. "condition": "Sunny",
  36. "temperature": "16",
  37. "humidity": "12"
  38. }
  39. ```