=begin = Weather-of-today plugin((-$Id: weather.rb,v 1.10 2008-03-02 09:01:46 kazuhiko Exp $-)) Records the weather when the diary is first updated for the date and displays it. == Acknowledgements The idea of this plugin is due to `hsbt'. The author took the hint for the implmentation from `zoe'. `kotak' kindly provided the information about NOAA. The author thanks to them. The author also appreciates National Weather Service (()) making such valuable data available in public domain as described in (()). == Copyright Copyright 2003 zunda Permission is granted for use, copying, modification, distribution, and distribution of modified versions of this work under the terms of GPL version 2 or later. =end =begin == Instance variables =end @weather_plugin_name = 'Weather-of-today' =begin == Classes and methods === WeatherTranslator module We want Japanese displayed in a diary written in Japanese. --- Weather::Words_en Array of arrays of a Regexp and a Statement to be executed. WeatherTranslator::S.tr accepts this kind of hash to translate a given string. No translations are defined for English. Please see an example in the Japanese resource. =end require 'erb' class Weather Words_en = [] end =begin === Weather class Weather of a date. --- Weather.html_string --- Weather.error_html_string Returns an HTML fragment showing data or error, called from Weather.to_html. --- Weather.i_html_string Returns a CHTML fragment to be shown on a mobile browser. =end class Weather include ERB::Util def error_html_string %Q|Weather error:#{h( @error )}| end # edit this method to define how you show the weather def html_string has_data = false r = '' # weather r << %Q|| has_condition = false if @data['weather'] then r << %Q|#{h( WeatherTranslator::S.new( @data['weather']).translate( Words_en ).compact.capitalize )}| has_condition = true has_data = true elsif @data['condition'] then r << %Q|#{h( WeatherTranslator::S.new( @data['condition']).translate( Words_en ).compact.capitalize )}| has_condition = true has_data = true end # temperature if @data['temperature(C)'] and t = @data['temperature(C)'].scan(/-?[\d.]+/)[-1] then r << ', ' if has_condition r << %Q| #{sprintf( '%.0f', 9.0/5.0 * t.to_f + 32.0 )} deg-F| has_data = true end r << '' # time stamp if @tz then tzbak = ENV['TZ'] ENV['TZ'] = @tz # this is not thread safe... end r << ' at ' if @data['timestamp'] then r << Time::at( @data['timestamp'].to_i ).strftime( '%H:%M' ).sub( /^0/, '' ) else r << Time::at( @time.to_i ).strftime( '%H:%M' ).sub( /^0/, '' ) end if @tz then ENV['TZ'] = tzbak end r << "" return has_data ? r : '' end # edit this method to define how you show the weather for a mobile agent def i_html_string r = '' # weather if @data['weather'] then r << %Q|| r << h( WeatherTranslator::S.new( @data['weather']).translate( Words_en ).compact.capitalize ) r << "" elsif @data['condition'] then r << %Q|| r << h( WeatherTranslator::S.new( @data['condition']).translate( Words_en ).compact.capitalize ) r << "" end return r end end # www configuration interface def weather_configure_html( conf ) station = Weather::extract_station_id(conf['weather.url']) station ||= conf['weather.url'] <<-HTML

Weather-of-today plugin

Records the weather when the diary is first updated for the date and displays it.

Data source

When you want to use e.g. NOAA National Weather Service, select your country from "Select a country..." in NOAA National Weather Service and push the "Go!" button. Then select the observation point. Write down the URL of the page shown in the box below. The four letter station ID can also be used here.

It would be better to record your time zone in the data if you are likely to move to another time zone in the future. Thus, the weather data will be shown in the local time where the diary is originally written.

To record timezone, add the following line into the tdiary.conf file in the directory tdiary.rb is: e.g. ENV['TZ'] = 'US/Pacific', or write it down the box below.

Display on a normal browser

Select from below:

Display on a mobile browser

Select from below:

Display to search engine robots

Select from below:

Other configurations

Other options can be configured by means of the tdiary.conf file. Please have a look in the plugin file: weather.rb if you want.

HTML end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End: