Skip to content
forked from davidchua/nea_api

Python Wrapper for NEA (nea.gov.sg)'s API

License

Notifications You must be signed in to change notification settings

codelah/nea_api

This branch is 2 commits behind davidchua/nea_api:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7fe9203 · Apr 10, 2016

History

10 Commits
Apr 10, 2016
Apr 9, 2016
Apr 9, 2016
Apr 9, 2016
Apr 9, 2016
Apr 10, 2016

Repository files navigation

NEA API Wrapper

Wrapper for the National Environment Agency of Singapore's Data API.

Disclaimer: This wrapper is NOT an official wrapper and do not attempt to represent NEA in anyway.

About

This wrapper has the following functions:

  • get_pm25()
  • get_2hr_nowcast()
  • get_24hrs_forecast()
  • get_4days_outlook()
  • get_heavy_rain_warning()
  • get_uvi()
  • get_earthquake()
  • get_psi_update()

All functions return an OrderedDict object which you can manipulate. The structure of the OrderedDict is the same as the original XML output.

Register for an API Key

To get an API key, you'll have to register at NEA's dataset API page

Installation

$ pip install nea_api

Usage

from nea_api import NEA

nea = NEA(api_key="<api key>")
results = nea.get_pm25()

# ipdb> results
OrderedDict([('channel', OrderedDict([('title', 'PM2.5 Update'), ('source', 'Airviro'), ('item', OrderedDict([('region', [OrderedDict([('id', 'rNO'), ('latitude', '1.41803'), ('longitude', '103.82000'), ('record', OrderedDict([('@timestamp', '20160406140000'), ('reading', OrderedDict([('@type', 'PM25_RGN_1HR'), ('@value', '17')]))]))]), OrderedDict([('id', 'rCE'), ('latitude', '1.35735'), ('longitude', '103.82000'), ('record', OrderedDict([('@timestamp', '20160406140000'), ('reading', OrderedDict([('@type', 'PM25_RGN_1HR'), ('@value', '27')]))]))]), OrderedDict([('id', 'rEA'), ('latitude', '1.35735'), ('longitude', '103.94000'), ('record', OrderedDict([('@timestamp', '20160406140000'), ('reading', OrderedDict([('@type', 'PM25_RGN_1HR'), ('@value', '19')]))]))]), OrderedDict([('id', 'rWE'), ('latitude', '1.35735'), ('longitude', '103.70000'), ('record', OrderedDict([('@timestamp', '20160406140000'), ('reading', OrderedDict([('@type', 'PM25_RGN_1HR'), ('@value', '26')]))]))]), OrderedDict([('id', 'rSO'), ('latitude', '1.29587'), ('longitude', '103.82000'), ('record', OrderedDict([('@timestamp', '20160406140000'), ('reading', OrderedDict([('@type', 'PM25_RGN_1HR'), ('@value', '30')]))]))])])]))]))])

Todo

  • Tests!

Reference

About

Python Wrapper for NEA (nea.gov.sg)'s API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%