ts stromgedacht
v2.1.0
使用 StromGedacht API 的 Typescript 库
在 npm 上可用。
npm install ts-stromgedacht
客户端可以提供当前时间的区域状态或给定时间段内的所有状态。
该期限最多可以延长至未来 2 天和过去 4 天。
每次提出请求时,您都需要提供您想要请求所在州的地区的邮政编码。
由于 API 允许所有来源,因此该库可以在浏览器中使用,而不会出现 CORS 错误。
只需从您的node_modules 导入客户端即可。
import { stromgedachtClient } from "ts-stromgedacht" ;
您可以通过调用Now
方法并传递该地区的邮政编码来获取该地区的当前状态。
const state = await stromgedachtClient . now ( "70173" ) ;
如果 api 返回错误,则此方法返回null
。如果邮政编码无效/不受支持,则可能会发生这种情况。
您可以通过调用States
方法并传递该地区的邮政编码、开始时间和结束时间来获取特定时间段内该地区的所有州。
const from = new Date ( "2023-01-01" ) ;
const to = new Date ( "2023-01-03" ) ;
const states = stromgedachtClient . states ( "70173" , from , to ) ;
开始和结束时间也可以是相对于当前时刻的小时数:
const hoursInPast = 24 ;
const hoursInFuture = 48 ;
const states = stromgedachtClient . statesRelative ( "70173" , hoursInPast , hoursInFuture ) ;
如果 api 返回错误,则此方法返回一个空数组。如果邮政编码无效/不受支持或超出支持的期限,则可能会发生这种情况。
您可以通过调用forecast
方法并传递该地区的邮政编码、开始时间和结束时间来获取特定时间段内该地区的天气预报。
const from = new Date ( "2023-01-01" ) ;
const to = new Date ( "2023-01-03" ) ;
const forecast = stromgedachtClient . forecast ( "70173" , from , to ) ;
该 API 限制为每分钟约 6 个请求。
以下是一些相关项目:
所使用的 API 由 StromGedacht, TransnetBW GmbH 提供。