File: traffic-update.l

package info (click to toggle)
euslisp 9.27%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 55,344 kB
  • sloc: ansic: 41,162; lisp: 3,339; makefile: 256; sh: 208; asm: 138; python: 53
file content (259 lines) | stat: -rw-r--r-- 6,983 bytes parent folder | download | duplicates (3)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
;;;; traffic-update.l
;;;; obtains traffic status infomation of the metropolitan-highway
;;;; and stores the html document in a postgresql table.

(require :http "http")
(require :time "time")
(require :webnews "webnews")
(require :pgsql "pgsql")

(defparameter *jartic-metro-highway-url*
	(url-pathname
	   "http://www.jartic.or.jp/traffic/highway/kousoku/rhm0001.html"))
(defparameter *jartic-ibaraki-highway-url*
	(url-pathname
	   "http://www.jartic.or.jp/traffic/highway/kousoku/rhm0005.html"))
(defparameter *jartic-tokyo-highway-url*
	(url-pathname
	   "http://www.jartic.or.jp/traffic/highway/kousoku/rhm0006.html"))

;; SQL to create weather table;
;;

#| 
drop table traffic_status;
drop sequence traffic_status_id_seq;

create table traffic_status (
	id serial,
	recdate date,
	rectime time,
	weekday int4,
	road symbol,
	traffic_status text
	);
|#

(defun update-traffic-status ()
  (let (now db split-html
	route6-pattern route-coast-pattern
	)
	(setq route6-pattern "6号")
	(setq route-coast-pattern "高速湾岸線")
	(setq route-joban-pattern "常磐道")
	(setq regulation-pattern "●主な規制情報")
	(setq triptime-pattern "●主な旅行時間")
	(setq closed-entry-pattern "●入口閉鎖")
	;
	;;
	;
	(setq metro-highway-body (cadr 
		(read-http *jartic-metro-highway-url*)))
	(setq ibaraki-highway-body (cadr
		(read-http *jartic-ibaraki-highway-url*)))
	(setq tokyo-highway-body (cadr
		(read-http *jartic-tokyo-highway-url*)))
	;;
	;; highway status information is composed of regulation, trip-time
	;; and closed-entry, in this order. 
	;;
	(setq metro-regulation-body (caar
		(html-marked-items metro-highway-body
			regulation-pattern '/table '/body)))
	(setq metro-triptime-body (caar
		(html-marked-items metro-highway-body
			triptime-pattern '/table '/body)))
	(setq metro-closed-entry-body (caar
		(html-marked-items metro-highway-body
			closed-entry-pattern '/table '/body)))
	;;
	(setq tokyo-regulation-body (car
		(html-marked-items tokyo-highway-body
			regulation-pattern '/table '/body)))
	(setq tokyo-triptime-body (car
		(html-marked-items tokyo-highway-body
			triptime-pattern '/table '/body)))
	;;
	(setq ibaraki-regulation-body (caar
		(html-marked-items ibaraki-highway-body
			regulation-pattern '/table '/body)))
	(setq ibaraki-triptime-body (car
		(html-marked-items ibaraki-highway-body
			triptime-pattern '/table '/body)))
	;;
	;; 首都高速6号線(向島,三郷) 
	;;
        (setq route6-regulation-info
		(concatenate-strings (car 
			(html-marked-items metro-regulation-body
				route6-pattern '/tr '/body t))))
	(setq route6-triptime-info
		(concatenate-strings (car 
			(html-marked-items metro-triptime-body
				route6-pattern '/tr '/body t))))
	(setq route6-closed-entry-info
		(concatenate-strings (car 
			(html-marked-items metro-closed-entry-body
				route6-pattern '/tr '/body t))))
	;;
	;; 首都高速湾岸線
	(setq coast-regulation-info
		(concatenate-strings (car 
			(html-marked-items metro-regulation-body
				route-coast-pattern '/tr '/body t))))
	(setq coast-triptime-info
		(concatenate-strings (car 
			(html-marked-items metro-triptime-body
				route-coast-pattern '/tr '/body t))))
	(setq coast-closed-entry-info
		(concatenate-strings (car 
			(html-marked-items metro-closed-entry-body
				route-coast-pattern '/tr '/body t))))
	;; 高速常盤道,茨城部
	(setq ibaraki-regulation-info
		(concatenate-strings (car 
			(html-marked-items ibaraki-regulation-body
				route-joban-pattern '/tr '/body t))))
	(setq ibaraki-triptime-info
		(concatenate-strings (car 
			(html-marked-items ibaraki-triptime-body
				route-joban-pattern '/tr '/body t))))
	;; 高速常盤道,東京部
	(setq tokyo-regulation-info
		(concatenate-strings (car 
			(html-marked-items tokyo-regulation-body
				route-joban-pattern '/tr '/body t))))
	(setq tokyo-triptime-info
		(concatenate-strings (car 
			(html-marked-items tokyo-triptime-body
				route-joban-pattern '/tr '/body t))))

	;;
	;; Insert the info into the database table
	;;
	(setq now (instance calendar-time :now))
	(setq db (instance pq:pgsql :init :dbname "t.matsui"))
	;;
	;; 首都高速6号ミサとせん
	(dolist (info route6-regulation-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'metro-route6
			'regulation
			info)) )
	(dolist (info route6-triptime-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'metro-route6
			'triptime
			info)) )
	(dolist (info route6-closed-entry-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'metro-route6
			'closed-entry
			info)) )
	;;;;; 湾岸線
	;;
	(dolist (info coast-regulation-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'metro-coast
			'regulation
			info)) )
	(dolist (info coast-triptime-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'metro-coast
			'triptime
			info)) )
	(dolist (info coast-closed-entry-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'metro-coast
			'closed-entry
			info)) )
	;;;;; JOUBANN IBARAKI
	;;
	(dolist (info IBARAKI-regulation-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'joban-ibaraki
			'regulation
			info)) )
	(dolist (info IBARAKI-triptime-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'joban-ibaraki
			'triptime
			info)) )
	;;;;; JOUBANN TOKYO
	;;
	(dolist (info tokyo-regulation-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'joban-tokyo
			'regulation
			info)) )
	(dolist (info tokyo-triptime-info)
	    (pq:insert-record2 db 'traffic_status
		'(recdate rectime weekday road infotype traffic_status)
		(list (send now :iso-date-string)
			(send now :iso-time-string)
			(send now :weekday)
			'joban-tokyo
			'triptime
			info))	)
	))