Livedoor weather HacksをSqueakで遊ぶ
手抜きですが、一応クラスにまとめてみる。
使い方:
| rec | rec := WeatherForecast query: 70 time: #tomorrow. Transcript show: rec title; cr; show: rec forecastDate; cr; show: rec description
クラスのコード:
'From Squeakland 3.8-05 of 7 September 2005 [latest update: #531] on 12 February 2006 at 12:01:19 am'! Object subclass: #WeatherForecast instanceVariableNames: 'url xmlDoc' classVariableNames: '' poolDictionaries: '' category: 'Experimental'! !WeatherForecast methodsFor: 'as yet unclassified' stamp: 'KR 2/11/2006 23:57'! contentOf: tagName ^(xmlDoc topElement firstTagNamed: tagName ) contentString convertFromWithConverter: (TextConverter newForEncoding: 'utf-8')! ! !WeatherForecast methodsFor: 'as yet unclassified' stamp: 'KR 2/11/2006 23:49'! query: locationID time: timeKeyword url := Url absoluteFromText: 'http://weather.livedoor.com/forecast/webservice/rest/v1?city=', locationID, '&day=' , timeKeyword. xmlDoc := XMLDOMParser parseDocumentFrom: (url retrieveContents contentStream ). ! ! !WeatherForecast methodsFor: 'accessing' stamp: 'KR 2/11/2006 23:53'! description ^self contentOf: #description ! ! !WeatherForecast methodsFor: 'accessing' stamp: 'KR 2/11/2006 23:57'! forecastDate ^self contentOf: #forecastdate! ! !WeatherForecast methodsFor: 'accessing' stamp: 'KR 2/11/2006 23:58'! publicTime ^self contentOf: #publictime! ! !WeatherForecast methodsFor: 'accessing' stamp: 'KR 2/11/2006 23:56'! telop ^self contentOf: #telop! ! !WeatherForecast methodsFor: 'accessing' stamp: 'KR 2/11/2006 23:59'! title ^self contentOf: #title! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! WeatherForecast class instanceVariableNames: ''! !WeatherForecast class methodsFor: 'as yet unclassified' stamp: 'KR 2/11/2006 23:51'! query: locationID time: timeKeyword | forecast | forecast := self new. forecast query: locationID time: timeKeyword. ^forecast! !