一个Python 3客户端从NWS天气预报API检索数据

nwswx的Python项目详细描述


NWSWX

python 3客户端,用于从NWS Weather Forecast API检索数据。

安装

pip install nwswx

要求

包生成要求

构建此模块所需的完整软件包列表可以在requirements.txt

中找到。

文档

完整的文档,包括示例和api引用:http://nwswx.readthedocs.io

示例

以geojson格式获取某个点的预测:

>>> import nwswx
>>> nws = nwswx.WxAPI('your@email.com')
>>> forecast = nws.point_forecast(39.0693, -94.6716)
>>> print(forecast)
{
    "@context": [
        "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
        {
            "wx": "https://api.weather.gov/ontology#",
            "geo": "http://www.opengis.net/ont/geosparql#",
            "unit": "http://codes.wmo.int/common/unit/",
            "@vocab": "https://api.weather.gov/ontology#"
        }
    ], ...

获取JSON-LD格式的点预测:

>>> import nwswx
>>> nws = nwswx.WxAPI('your@email.com')
>>> forecast = nws.point_forecast(39.0693, -94.6716, return_format=nwswx.formats.JSONLD)
>>> print(forecast['periods'])
[{'number': 1, 'name': 'Tonight', 'startTime': '2019-01-13T22:00:00-08:00', 'endTime':
'2019-01-14T06:00:00-08:00', 'isDaytime': False, 'temperature': 28, 'temperatureUnit':
'F', 'temperatureTrend': None, 'windSpeed': '2 to 6 mph', 'windDirection': 'N',
'icon': 'https://api.weather.gov/icons/land/night/few?size=medium', 'shortForecast':
'Mostly Clear', 'detailedForecast': 'Mostly clear, with a low around 28. North wind 2
to 6 mph.'}, ...

以json-ld格式获取点的每小时预测:

>>> import nwswx
>>> nws = nwswx.WxAPI('your@email.com')
>>> forecast = nws.point_hourly_forecast(39.0693, -94.6716, return_format=nwswx.formats.JSONLD)
>>> print(forecast['periods'])
[{'number': 1, 'name': '', 'startTime': '2019-01-16T19:00:00-08:00', 'endTime':
'2019-01-16T20:00:00-08:00', 'isDaytime': False, 'temperature': 42,
'temperatureUnit': 'F', 'temperatureTrend': None, 'windSpeed': '10 mph', 'windDirection':
'NE', 'icon': 'https://api.weather.gov/icons/land/night/rain,90?size=small',
'shortForecast': 'Light Rain', 'detailedForecast': ''}, ...

获取Atom格式的点的活动天气警报:

>>> import nwswx
>>> nws = nwswx.WxAPI('your@email.com')
>>> alerts = nws.active_alerts({'point': '39.0693,-94.6716'}, return_format=nwswx.formats.ATOM)
>>> print(alerts)
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:cap="urn:oasis:names:tc:emergency:cap:1.2">
 <id>https://api.weather.gov/alerts?point=39.0693%2C-94.6716&amp;active=1&amp;zone=KSZ104%2CKSC209</id>
 <generator>NWS CAP Server</generator>
 <updated>2019-01-17T06:04:28+00:00</updated>
 <author>
  <name>w-nws.webmaster@noaa.gov</name>
 </author>
 <title>current watches, warnings, and advisories for 39.0693 N, 94.6716 W</title>
 <link rel="self" href="https://api.weather.gov/alerts?point=39.0693%2C-94.6716&amp;active=1&amp;zone=KSZ104%2CKSC209"/>
 <entry>
  <id>https://api.weather.gov/alerts/NWS-IDP-PROD-3320294-2901037</id>
  <link rel="alternate" href="https://api.weather.gov/alerts/NWS-IDP-PROD-3320294-2901037"/>
  <updated>2019-01-16T14:52:00-06:00</updated>
  <published>2019-01-16T14:52:00-06:00</published>
  <author>
   <name>NWS</name>
  </author>
  <title>Winter Weather Advisory issued January 16 at 2:52PM CST expiring January 17 at 9:00AM CST by NWS Kansas City/Pleasant HIll MO</title>
...

限制,其中有许多

尚未实现以下终结点列表:

  • /stations
  • /stations/{stationId}
  • /stations/{stationId}/observations
  • /stations/{stationId}/observations/current
  • /stations/{stationId}/observations/{recordId}
  • /products/{productId}
  • /products/types
  • /products/types/{typeId}
  • /products/types/{typeId}/locations
  • /products/types/{typeId}/locations/{locationId}
  • /products/locations
  • /products/locations/{locationId}/types
  • /offices/{officeId}
  • /zones/{type}/{zoneId}
  • /zones/{type}/{zoneId}/forecast
  • /alerts/active/count
  • /alerts/active/zone/{zoneId}
  • /alerts/active/area/{area}
  • /alerts/active/region/{region}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jenkins在java代码的csv中使用前导零传递数字   终止java应用程序javaw。exe eclipse   java平均字长。文本   java在事务中关闭连接时会发生什么?   java如何为rich faces extendedDatatable启用可调整大小的列?   SpringJavaWebApp头nosniff不适合js和css文件   Java:抛出异常   java获取拒绝ArrayList中存在的用户名的代码。   关于编写JNDI服务提供者的java教程   java Android emulator电子书示例已停止   java如何防止双向关系中的循环   在Java中,如何将接口的实现作为变量传递给方法?   java有没有办法通过注释来监听CoreNLP处理的进度?   java Eclipse错误:导入项目时“无法读取项目描述文件”   java为什么findViewById返回null?