1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Codeを使って今日の天気を返すWebAPIを作成する手順

1
Last updated at Posted at 2026-01-21

はじめに

天気を取得するWeb APIが必要になったので作ろうと思ったら、Claude Codeを使って10分で作れたから手順を記します。

準備

Claude Codeのインストール

以下のコマンドを実行

curl -fsSL https://claude.ai/install.sh | bash

Githubにリポジトリを作成

weather-apiというリポジトリを作成

リポジトリをクローン

以下のコマンドでリポジトリをコピー

git clone https://github.com/shinob/weather-api.git

開発

プロジェクトの要件を整理

やりたいこととやって欲しいことを整理して"project.md"に書き出す

prompt.md
# 目的

気象庁JSONデータから今日の天気を取得するWeb APIを作りたい
地域を"area_code"で指定
例えば、"3220100"は"松江市"

# 予報値取得の流れ

- 気象庁のJSON API(`https://www.jma.go.jp/bosai/forecast/data/forecast/{office_code}.json`)を利用
- area_codeから親のoffice_code(都道府県コード)を特定
- 天気予報JSONから今日のデータを抽出
- 地域、対象日、天気、取得日時をJSON形式で返す

# 仕様

- Python3
- できるだけ一般的なライブラリを使用
- 引数は"area_code"
- 仮想環境を使用
- 出力形式は"JSON"

Claude Codeを実行

以下のコマンドを入力

cd weather-api
claude

初期化

以下のコマンドを入力しディレクトリの内容をClaude Codeに理解してもらう

/init

開発を実行

以下のプロンプトを入力

@project.md のとおり完成させて下さい

途中質問が出たらエンターキーを押して続けてさせていると、少し待ったら完成

テスト

環境構築

以下のコマンド入力してセットアップ

python3 -m venv venv
./venv/bin/pip install -r requirements.txt

コマンドでテスト

以下のコマンドを入力して結果を確認

./venv/bin/python weather.py 3220100

以下の結果が返ってきます

{
  "area": "松江市",
  "date": "2026-01-22",
  "weather": "雪 所により 雷 を伴う",
  "weather_code": "400",
  "pops": [
    "60",
    "60",
    "50",
    "50"
  ],
  "temps": {
    "min": "3",
    "max": "3"
  },
  "fetched_at": "2026-01-22T06:31:17.763160",
  "report_datetime": "2026-01-22T05:00:00+09:00"
}

Web APIを起動

以下のコマンドでポート番号を指定して起動

PORT=3000 ./venv/bin/python app.py

以下のように表示されれば起動成功

INFO:     Started server process [58622]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit)

Web APIをテスト

以下のコマンドを実行

curl -s "http://localhost:3000/forecast?area_code=3220100" | jq

以下のような返答があれば成功

{
  "area": "松江市",
  "date": "2026-01-22",
  "weather": "雪 所により 雷 を伴う",
  "weather_code": "400",
  "pops": [
    "60",
    "60",
    "50",
    "50"
  ],
  "temps": {
    "min": "3",
    "max": "3"
  },
  "fetched_at": "2026-01-22T06:39:09.530262",
  "report_datetime": "2026-01-22T05:00:00+09:00"
}

できました、できました、思いついただけでできました!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?