@trashwbin/weather-service
Version:
A weather service that provides weather alerts and forecasts using the National Weather Service API
65 lines (40 loc) • 1.18 kB
Markdown
# Weather Service
一个基于国家气象服务(National Weather Service)API 的天气服务,提供天气预报和天气警报功能。
## 功能特点
- 获取指定州的天气警报
- 获取指定坐标的天气预报
- 支持 TypeScript
- 基于 MCP SDK
## 安装
```bash
npm install @abin/weather-service
```
## 使用方法
### 作为命令行工具
安装后可以直接使用 `weather` 命令:
```bash
weather
```
### 作为模块导入
```typescript
import { WeatherService } from '@abin/weather-service';
const weatherService = new WeatherService();
// 获取天气警报
const alerts = await weatherService.getAlerts('CA');
// 获取天气预报
const forecast = await weatherService.getForecast(37.7749, -122.4194);
```
## API 文档
### getAlerts(state: string)
获取指定州的天气警报。
- `state`: 两字母的州代码(例如:'CA', 'NY')
- 返回:包含警报信息的对象
### getForecast(latitude: number, longitude: number)
获取指定位置的天气预报。
- `latitude`: 纬度 (-90 到 90)
- `longitude`: 经度 (-180 到 180)
- 返回:包含天气预报信息的对象
## 许可证
MIT
## 作者
Abin