| name | alibabacloud-iqs-weather-query |
| description | 7-day weather forecast query powered by Alibaba Cloud IQS web search and page reading.
Triggers: "weather forecast", "7-day weather", "weekly weather", "weather in [city]", "will it rain", "temperature forecast"
|
IQS Weather Query - 7-Day Weather Forecast
Query 7-day weather forecasts for any city using Alibaba Cloud IQS web search (UnifiedSearch) and page reading (ReadPageBasic) capabilities.
Underlying Service: alibabacloud-iqs-search
Hybrid Parsing Strategy:
- Known sites (weather.cma.cn, weather.com.cn): Dedicated parsers extract structured JSON โ
parseMode: "structured"
- Unknown sites: ReadPage extracts main content (readabilityMode: article), returns raw text with extraction hint โ
parseMode: "raw", agent (LLM) interprets directly
| Output Field | Description |
|---|
| parseMode | "structured" (parsed JSON) or "raw" (text for agent) |
| weather | Weather condition (sunny, cloudy, rain, etc.) |
| temperature | Temperature range |
| windSpeed | Wind speed/level |
| windDirection | Wind direction |
Environment Configuration
Pre-check: ALIYUN_IQS_API_KEY Required
if [ -z "$ALIYUN_IQS_API_KEY" ]; then echo "API Key ๆช้
็ฝฎ"; else echo "API Key ๅทฒ้
็ฝฎ(ๅทฒ่ฑๆ)"; fi
If output is 'API Key ๆช้
็ฝฎ', the API Key is not configured.
How to obtain ALIYUN_IQS_API_KEY: Please refer to Aliyun IQS Documentation
Configure environment variable (choose one):
Option 1: Temporary (current terminal session only)
export ALIYUN_IQS_API_KEY="your-api-key-here"
Option 2: Permanent (recommended)
Add to ~/.zshrc or ~/.bashrc:
export ALIYUN_IQS_API_KEY="your-api-key-here"
Run source ~/.zshrc or source ~/.bashrc to apply.
Alternative: Place API Key in ~/.alibabacloud/iqs/env file:
ALIYUN_IQS_API_KEY=your-api-key-here
Workflow
User Input (city name)
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 1: UnifiedSearch โ Search: "{city} ๅคฉๆฐ้ขๆฅ ๆชๆฅ7ๅคฉ"
โ (Web Search) โ Priority: weather.cma.cn > weather.com.cn
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ Best weather URL
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 2: ReadPageBasic โ Known site โ readabilityMode: normal
โ (Page Reading) โ Unknown site โ readabilityMode: article
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ Page content
โผ
Known site?
โฑ โฒ
YES NO
โ โ
โผ โผ
Parser Return rawText
Router + hint for agent
โ (parseMode: raw)
โผ
Structured JSON
(parseMode: structured)
Usage
Prerequisites
- Node.js >= 18 (native
fetch support required)
- No additional npm dependencies needed
Execute Query
node scripts/weather.mjs <city>
Examples:
node scripts/weather.mjs ๅไบฌ
node scripts/weather.mjs ไธๆตท
node scripts/weather.mjs ๆญๅท
node scripts/weather.mjs Tokyo
Output Format
Structured mode (known sites โ parsed successfully):
{
"success": true,
"data": {
"city": "ๅไบฌ",
"parseMode": "structured",
"queryTime": "2026-03-26T10:00:00.000Z",
"forecastDays": 7,
"forecast": [
{
"date": "3ๆ26ๆฅ",
"weather": "ๆด",
"temperature": "5ยฐC ~ 18ยฐC",
"windDirection": "ๅ้ฃ",
"windSpeed": "3-4็บง"
}
],
"source": "https://weather.cma.cn/..."
}
}
Raw mode (unknown sites โ agent interprets the text):
{
"success": true,
"data": {
"city": "ๅไบฌ",
"parseMode": "raw",
"hint": "ไปฅไธๆฏๅไบฌๅคฉๆฐ็ฝ้กต็ๆญฃๆๅ
ๅฎน๏ผ่ฏทไปไธญๆๅๆชๆฅ7ๅคฉ็ๅคฉๆฐ้ขๆฅไฟกๆฏ...",
"rawText": "ๅไบฌๅคฉๆฐ้ขๆฅ\nไปๅคฉ ๆด 18ยฐC/5ยฐC ...",
"evolveHint": "[ๆ็ปญ่ฟๅ] ๅฝๅ็ซ็น \"example.com\" ๆฒกๆๅน้
็่งฃๆๅจ...",
"source": "https://example.com/weather/beijing"
}
}
IQS APIs Used
| API | Endpoint | Purpose | Documentation |
|---|
| UnifiedSearch | cloud-iqs.aliyuncs.com/search/unified | Web search for weather pages | Doc |
| ReadPageBasic | cloud-iqs.aliyuncs.com/readpage/scrape | Read and parse weather webpage | Doc |
Search Priority Sites (with dedicated parsers):
- weather.cma.cn (China Meteorological Administration) โ
parseCmaWeather โ readabilityMode: normal
- baidu.weather.com.cn / sq.weather.com.cn (China Weather Network mobile) โ
parseBaiduWeatherComCn โ readabilityMode: normal
- weather.com.cn (China Weather Network, all other subdomains) โ
parseWeatherComCn โ readabilityMode: normal
- Other sites โ no parser, return raw text โ readabilityMode:
article (cleaner body extraction)
Error Handling
| Error Code | Description | Solution |
|---|
| CREDENTIALS_MISSING | API Key not configured | Set ALIYUN_IQS_API_KEY environment variable |
| NO_RESULTS | No weather results found | Check city name is correct |
| QUERY_FAILED | API call failed | Check network, verify credentials |
| PARSE_FAILED | Failed to parse weather data from webpage | The target site's page structure may have changed; update the corresponding parser or add a new one (see Extending section) |
Best Practices
- Use Chinese city names for domestic weather queries for better accuracy
- Node.js >= 18 required - native
fetch API is used, no npm install needed
- Cache awareness - ReadPage uses
maxAge not set, always fetches latest data
- Extensible parsers - Each weather site has its own parser; add new sites by registering in
PARSER_REGISTRY
Continuous Evolution
This skill is designed to self-improve over time. When the script encounters an unknown site format (no matching parser), it returns parseMode: "raw" with an evolveHint field.
Agent behavior when parseMode is "raw":
- First: Answer the user โ Extract weather info from
rawText using LLM understanding and respond to the user immediately.
- Then: Evolve โ Read the
evolveHint and analyze the rawText format pattern, then write a new parser function and register it in PARSER_REGISTRY (see Extending section below). This ensures that next time the same site format is hit, it goes through structured mode directly.
First query for unknown site:
search โ readpage โ no parser match โ raw mode โ agent answers user
โ agent writes new parser โ evolveHint
Subsequent queries for same site:
search โ readpage โ parser match โ structured mode โ direct JSON output
Key: The skill gets smarter with every new city searched. Each raw-mode encounter is an opportunity to add a new parser, progressively covering more site formats.
Extending: Add a New Weather Site Parser
The script uses a Parser Registry pattern. Each weather site has its own dedicated parser function, and the router automatically dispatches based on URL. To add support for a new site, follow these 3 steps:
Step 1: Write a Parser Function
Add a new parser function in scripts/weather.mjs. It must accept (content, city) and return the standard format:
function parseMyNewSite(content, city) {
const forecast = [];
return {
city,
queryTime: new Date().toISOString(),
forecastDays: Math.min(forecast.length, 7),
forecast: forecast.slice(0, 7),
raw: forecast.length === 0 ? content.substring(0, 2000) : undefined,
};
}
Return format for each forecast item:
| Field | Type | Example |
|---|
| date | string | "04/07 ๆๆไบ" |
| weather | string | "ๆด่ฝฌๅคไบ" |
| temperature | string | "5ยฐC ~ 18ยฐC" |
| windDirection | string | "ๅ้ฃ" |
| windSpeed | string | "3-4็บง" |
Step 2: Register in PARSER_REGISTRY
Add your parser to the registry array at the top of weather.mjs. Order matters โ higher position = higher priority:
const PARSER_REGISTRY = [
{ pattern: 'weather.cma.cn', parser: parseCmaWeather },
{ pattern: 'baidu.weather.com.cn', parser: parseBaiduWeatherComCn },
{ pattern: 'sq.weather.com.cn', parser: parseBaiduWeatherComCn },
{ pattern: 'weather.com.cn', parser: parseWeatherComCn },
{ pattern: 'mynewsite.com', parser: parseMyNewSite },
];
Step 3: Add to Search Priority (optional)
If you want the new site to be prioritized in search results, add it to PREFERRED_WEATHER_SITES:
const PREFERRED_WEATHER_SITES = [
'weather.cma.cn',
'weather.com.cn',
'mynewsite.com',
];
How the Router Works
parseWeatherData(content, city, url)
โ
โโ URL contains "weather.cma.cn"? โ parseCmaWeather(content, city)
โโ URL contains "baidu.weather.com.cn"? โ parseBaiduWeatherComCn(content, city)
โโ URL contains "sq.weather.com.cn"? โ parseBaiduWeatherComCn(content, city)
โโ URL contains "weather.com.cn"? โ parseWeatherComCn(content, city)
โโ URL contains "mynewsite.com"? โ parseMyNewSite(content, city)
โ
โโ No match or result < 3 days? โ return rawText + hint (agent interprets)
Tip: Use node -e "..." with the ReadPage API to fetch and inspect the raw text format of a new site before writing the parser. See existing parsers (parseCmaWeather, parseWeatherComCn) as reference implementations.