-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjma-area.el
163 lines (123 loc) · 4.64 KB
/
jma-area.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;;; jma-area.el --- JMA Area -*- lexical-binding: t; -*-
;; Copyright (C) 2022 AKIYAMA Kouhei
;; Author: AKIYAMA Kouhei <misohena@gmail.com>
;; Keywords: comm
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'jma-utils)
;;;; 発表区域
(defvar jma-area-data-cache nil)
(defun jma-area-data-get ()
(or jma-area-data-cache
(setq jma-area-data-cache
(jma-json-get
"https://www.jma.go.jp/bosai/common/const/area.json"))))
;;;;; 一覧取得
(defun jma-area-centers ()
(alist-get 'centers (jma-area-data-get)))
(defun jma-area-offices ()
(alist-get 'offices (jma-area-data-get)))
(defun jma-area-class10s ()
(alist-get 'class10s (jma-area-data-get)))
(defun jma-area-class15s ()
(alist-get 'class15s (jma-area-data-get)))
(defun jma-area-class20s ()
(alist-get 'class20s (jma-area-data-get)))
;;;;; 検索
(defun jma-area-center (center-code)
(assq
(jma-ensure-symbol center-code)
(jma-area-centers)))
(defun jma-area-office (office-code)
(assq
(jma-ensure-symbol office-code)
(jma-area-offices)))
(defun jma-area-class10 (class10-code)
(assq
(jma-ensure-symbol class10-code)
(jma-area-class10s)))
(defun jma-area-class15 (class15-code)
(assq
(jma-ensure-symbol class15-code)
(jma-area-class15s)))
(defun jma-area-class20 (class20-code)
(assq
(jma-ensure-symbol class20-code)
(jma-area-class20s)))
;;;;; 区域オブジェクトに対するアクセッサ
(defun jma-area-code-symbol (area-obj)
(car area-obj))
(defun jma-area-code (area-obj)
(symbol-name (jma-area-code-symbol area-obj)))
(defun jma-area-name (area-obj)
(alist-get 'name (cdr area-obj)))
(defun jma-area-office-name (area-obj)
(alist-get 'officeName (cdr area-obj)))
(defun jma-area-parent-code (area-obj)
(alist-get 'parent (cdr area-obj)))
(defun jma-area-child-codes (area-obj)
(alist-get 'children (cdr area-obj)))
;;;;; 府県予報区-二次細分区域 対応関係
(defun jma-area-class20-codes-in-office (office-code)
"府県予報区OFFICE-CODEの中の全二次細分区域コードを返します。"
(seq-mapcat
(lambda (class15-code)
(jma-area-child-codes (jma-area-class15 class15-code)))
(seq-mapcat
(lambda (class10-code)
(jma-area-child-codes (jma-area-class10 class10-code)))
(jma-area-child-codes (jma-area-office office-code)))))
;;;;; ユーザー入力
(defun jma-area-read-center (&optional prompt)
"ミニバッファから地方予報区を読み取ります。"
(jma-choose-from-alist
(or prompt "地方予報区: ")
(mapcar (lambda (center)
(cons
(jma-area-name center)
(jma-area-code center)))
(jma-area-centers))))
;;(jma-area-read-center)
(defun jma-area-read-office (&optional prompt)
"ミニバッファから府県予報区(概ね都道府県)を読み取ります。"
(jma-choose-from-alist
(or prompt "府県予報区: ")
(mapcar (lambda (office)
(cons
(jma-area-name office)
(jma-area-code office)))
(jma-area-offices))))
;;(jma-area-read-office)
(defun jma-area-read-class10 (office-code &optional prompt)
"ミニバッファから一次細分区域を読み取ります。"
(jma-choose-from-alist
(or prompt "一次細分区域: ")
(mapcar (lambda (class10-code)
(cons
(jma-area-name (jma-area-class10 class10-code))
class10-code))
(jma-area-child-codes (jma-area-office office-code)))))
;;(jma-area-read-class10 "130000")
(defun jma-area-read-class20-in-office (office-code &optional prompt)
"ミニバッファから二次細分区域(概ね市区町村)を読み取ります。"
(jma-choose-from-alist
(or prompt "二次細分区域: ")
(mapcar (lambda (class20-code)
(cons
(jma-area-name (jma-area-class20 class20-code))
class20-code))
(jma-area-class20-codes-in-office office-code))))
;;(jma-area-read-class20-in-office "130000")
(provide 'jma-area)
;;; jma-area.el ends here