solcast ts
NPM release
ไลบรารี TypeScript สำหรับการสืบค้น Solcast API Async/Promise ตาม
โมดูลนี้ช่วยให้ผู้ใช้ที่ลงทะเบียนสามารถสอบถาม Solcast API https://api.solcast.com.au คุณจะต้องลงทะเบียนบัญชีผู้ใช้ของคุณเพื่อรับคีย์ API https://solcast.com.au/api/register หากไม่มีคีย์ API คุณจะไม่สามารถรับผลลัพธ์ API ที่ถูกต้องได้สำเร็จ
ส่งคืนสัญญา Powerforecast ที่ตำแหน่งของอินพุตจุด latlng
export interface PowerForecast {
forecasts: Forecast [ ] ;
}
export interface Forecast {
period_end: Date ;
period: string ;
pv_estimate: number ;
} ส่งคืนสัญญา RadiationForecast ที่ตำแหน่งของอินพุต Latlng Point
export interface RadiationForecast {
forecasts: Forecast [ ] ;
}
export interface Forecast {
ghi: number ;
ghi90: number ;
ghi10: number ;
ebh: number ;
dni: number ;
dni10: number ;
dni90: number ;
dhi: number ;
air_temp: number ;
zenith: number ;
azimuth: number ;
cloud_opacity: number ;
period_end: Date ;
period: string ;
}คุณสามารถใช้ตัวแปรสภาพแวดล้อมมาตรฐานเพื่อเก็บคีย์ API ของคุณและไม่จำเป็นต้องผ่านวัตถุตัวเลือก {Radiation | Power} เสริมในแต่ละฟังก์ชั่น
ชื่อตัวแปรสภาพแวดล้อม
SOLCAST_API_KEY
SOLCAST_API_URL
สามารถเข้าถึงได้ผ่านตัวแปรสภาพแวดล้อมกระบวนการทั่วไป
process.env.SOLCAST_API_KEY
process.env.SOLCAST_API_URL
import * as solcast from 'solcast' ;
const point = solcast . latLng ( - 33.865143 , 151.209900 ) ; // Sydney, Australia
const radiationOptions = solcast . Options . radiation ( ) ;
radiationOptions . APIKey = 'YOUR API KEY HERE' ;
const promiseFn = solcast . Radiation . forecast ( point , radiationOptions ) ;
promiseFn . then ( results => {
console . log ( results ) ;
} )
. catch ( err => {
console . log ( err ) ;
} ) ; const solcast = require ( 'solcast' ) ;
const point = solcast . latLng ( - 33.865143 , 151.209900 ) ; // Sydney, Australia
const radiationOptions = solcast . Options . radiation ( ) ;
radiationOptions . APIKey = 'YOUR API KEY HERE' ;
const fn = async function ( ) {
return await solcast . Radiation . forecast ( point , radiationOptions )
} ;
fn ( ) . then ( results => {
console . log ( results ) ;
} )
. catch ( err => {
console . log ( err ) ;
} ) ; const solcast = require ( 'solcast' ) ;
const point = solcast . latLng ( - 33.865143 , 151.209900 ) ; // Sydney, Australia
const radiationOptions = solcast . Options . radiation ( ) ;
radiationOptions . APIKey = 'YOUR API KEY HERE' ;
const results = solcast . Radiation . forecast ( point , radiationOptions ) ;
results . then ( results => {
console . log ( results ) ;
} )
. catch ( err => {
console . log ( err ) ;
} ) ; { forecasts:
[ { ghi: 0,
ghi90: 0,
ghi10: 0,
ebh: 0,
dni: 0,
dni10: 0,
dni90: 0,
dhi: 0,
air_temp: 10,
zenith: 103,
azimuth: -88,
cloud_opacity: 3,
period_end: '2017-08-31T19:30:00.0000000Z',
period: 'PT30M' },
...
]
}
.env.json.sample to .env.jsonSOLCAST_API_KEY บนไฟล์ json หลังจากลงทะเบียนจาก https://solcast.com.au/api/register/