Add support for Japanese fire department emergency dispatch data scraping to a Rust application that provides unified JSON format outputs
このスキルは、日本の消防署からの緊急出動情報をスクレイピングし、統一されたJSON形式で提供するRustアプリケーションに新しい市区町村のサポートを追加します。
This skill helps you add support for new Japanese municipalities to the emergency-dispatch system. It guides you through:
When the user asks to add support for a new municipality:
1. **Verify the Municipal Code**
- Fetch the authoritative data: `curl https://jmc.osumiakari.jp/joint_all.json`
- Search for the municipality name in the JSON response
- Extract the correct 6-digit JIS X 0402 code
- **NEVER guess or assume the code** - always verify from this source
- If multiple municipalities share a fire department (一部事務組合), each gets its own parser with its own verified code
2. **Analyze the Target Website**
- Visit the fire department's website URL
- Identify the HTML structure and patterns (look for markers like `◆現在の出動`, `出動情報`, `災害情報`)
- Check the character encoding (look for `<meta charset>` tags)
- Note any special formatting requirements for time, address, or disaster type
- Compare with existing parsers in `src/parse/` to find similar patterns
3. **Create the Parser File**
- Create `src/parse/parse_XXXXXX.rs` (where XXXXXX is the verified 6-digit code)
- Implement `pub fn return_XXXXXX() -> Result<(), Box<dyn std::error::Error>>`
- Use `HttpRequestConfig` for HTTP requests with appropriate configuration:
- Start with default encoding (UTF-8)
- Only add `.with_shift_jis(true)` if the website specifically uses Shift_JIS
- Add custom headers if needed using `.with_accept()`, `.with_accept_language()`, etc.
- Parse the HTML using `scraper` crate with CSS selectors
- **CRITICAL**: Use UTF-8 safe string operations:
- Always use `.split()` for text extraction between markers
- Never use `find()` indices with slice operations like `&text[start..end]`
- Use `.replace()` for simple character removal
- Chain operations with `.unwrap_or()` for graceful error handling
- Output JSON to `dist/XXXXXX.json` with this exact structure:
```json
{
"disasters": [
{
"address": "Full address starting with prefecture",
"time": "HH:MM format time",
"type": "Type of emergency dispatch"
}
],
"jisx0402": "6-digit municipal code",
"source": [
{
"name": "Fire department name",
"url": "Source website URL"
}
]
}
```
4. **UTF-8 Safe Text Processing Examples**
Extract text between markers:
```rust
let extracted = text
.split(start_marker).nth(1)
.and_then(|s| s.split(end_marker).next())
.unwrap_or("");
```
Remove unwanted patterns:
```rust
let cleaned = text.replace(unwanted_pattern, "");
```
Format time (convert Japanese characters):
```rust
let formatted_time = raw_time
.replace("時", ":")
.replace("分", "");
```
5. **Integrate the Parser**
- Add to `src/parse/mod.rs`: `pub mod parse_XXXXXX;`
- Add import to `src/lib.rs`: `use crate::parse::parse_XXXXXX::return_XXXXXX;`
- Add function call in `get_all()` in `src/lib.rs`: `return_XXXXXX()?;`
6. **Update Documentation**
- Add the municipality to the "対応市区町村" section in `README.md`
- Include: municipality name, fire department name, and verified 6-digit code
7. **Test the Implementation**
- Run `cargo check` to verify compilation
- Run `cargo run` to execute all parsers including the new one
- Verify `dist/XXXXXX.json` is created with correct format
- Check that the new municipality appears in `dist/list.json` and `dist/all.json`
- Verify no UTF-8 panics occur with Japanese text processing
**Time formatting**: `text.replace("時", ":").replace("分", "")`
**Address extraction**:
```rust
let address = text
.split(city_marker).nth(1).unwrap_or("")
.split(suffix_marker).next().unwrap_or("")
.trim();
```
**Empty state check**: Look for phrases indicating no current dispatches
**Section extraction**: Use markers like `◆`, `●`, `・` to identify sections
Adding support for a city with verified code 272213:
1. Verify code from jmc.osumiakari.jp
2. Create `src/parse/parse_272213.rs` with `return_272213()` function
3. Add module declaration, import, and function call
4. Update README.md
5. Run `cargo run` to test
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/emergency-dispatch-parser/raw