Skip to main content

Unofficial Python wrapper for the BMKG (Meteorology, Climatology, and Geophysical Agency) API.

Project description

bmkg pypi downloads Build Status license BLAZINGLY FAST!!!

Unofficial Python wrapper for the BMKG (Meteorology, Climatology, and Geophysical Agency) API.

Installation

$ pip install bmkg

Examples

Fetching the weather of a specific province
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch a weather forecast from a province
    weather = await client.get_forecast(bmkg.Province.JAKARTA)
    
    # get the weather forecast across various locations
    for forecast in weather.forecasts:
    
      # temperature of this forecast across various timeframes
      for temp in weather.temperature:
        print(f'temperature at {temp.date!r} is {temp.value!r}')

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())
Fetching the latest earthquake
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch the latest earthquake
    earthquake = await client.get_latest_earthquake()
    
    print(repr(earthquake))

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())
Fetching the most recent earthquakes magnitude 5 or higher
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch the most recent earthquakes magnitude 5 or higher
    earthquakes = await client.get_recent_earthquakes()
    
    # iterate through the generator
    for earthquake in earthquakes:
      print(repr(earthquake))

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())
Fetching the most recent earthquakes regardless of their magnitude
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch the most recent earthquakes regardless of their magnitude
    earthquakes = await client.get_felt_earthquakes()
    
    # iterate through the generator
    for earthquake in earthquakes:
      print(repr(earthquake))

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bmkg-1.0.4.tar.gz (11.0 kB view hashes)

Uploaded Source

Built Distribution

bmkg-1.0.4-py3-none-any.whl (16.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page