Difference between revisions of "MythWeather Grabber Script Format"

From MythTV Official Wiki
Jump to: navigation, search
(shamelessly stolen from mythvideo_grabber_script_format)
 
m (edit category)
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
MythWeather grabber scripts are small executable perl, python, or binary applications which query online sources of weather and return it in a format parseable by MythWeather.  This page documents the current format required of the grabber scripts to function.
 
MythWeather grabber scripts are small executable perl, python, or binary applications which query online sources of weather and return it in a format parseable by MythWeather.  This page documents the current format required of the grabber scripts to function.
  
== The Version Command (-v) ==
+
= Data Types =
  
All grabber scripts must return an identifying string when run with the '-v' argument. The command returns a comma separated list of the script name, script version, author, and author's email, and output must end with a newline character.
+
MythWeather has six different types of pages. Grabbers are categorized into these types by the data they specify as capable of providing. Grabbers can seamlessly provide data for multiple pages by making sure to meet all the requirements for each.
  
<pre>
+
== Current Conditions ==
#./bbccurrentxml.pl -v
+
* cclocation
BBC-Current-XML,0.2,Stuart Morgan,stuart@tase.co.uk
+
* relative_humidity
</pre>
+
* pressure
 +
* wind_spdgst
 +
* wind_dir
 +
* visibility
 +
* appt
 +
* temp
 +
* weather
 +
* weather_icon
 +
* observation_time
 +
* copyright
  
 +
== Three Day Forecast ==
 +
* 3dlocation
 +
* date-0 through date-2
 +
* icon-0 through icon-2
 +
* low-0 through low-2
 +
* high-0 through high-2
 +
* updatetime
  
== The Timeout Command (-T) ==
+
== Six Day Forecast ==
 +
* 6dlocation
 +
* date-0 through date-5
 +
* icon-0 through icon-5
 +
* high-0 through high-5
 +
* low-0 through low-5
  
All grabber scripts must return two timeout values when run with the '-T' argument. The command returns a comma separated list of information lifetime, and web response timeout, in seconds.
+
<!--
 +
== Today's Forecast ==
 +
* header
 +
* updatetime
 +
* today-desc
 +
-->
 +
==  Static Map ==
 +
A static map is an image, which is downloaded to a local file by the
 +
grabber. The map is a string like /dir1/dir2/filename-600x800. This
 +
represents a local file  /dir1/dir2/filename with an image sized
 +
600x800. The '-600x800' suffix is not mandatory, if missing the image
 +
will be expanded to fill the window.
 +
 
 +
Data provided:
 +
 
 +
* smdesc
 +
* updatetime
 +
* map
 +
* copyright
 +
 
 +
== Animated Map ==
 +
An animation is typically downloaded as a single file. The grabber
 +
splits it into separate files which are stored locally. These files
 +
are represented by a single animation string like
 +
/dir1/dir2/filename-%1-6-800x600.
 +
   
 +
The %1 part is replaced with a unique number for each file. So with 
 +
animation like above there will be files like filename-0,
 +
filename-1 etc.
 +
   
 +
The '6' digit is the number of files. For this example, there will be
 +
6 files named filename-0..filename-5
 +
   
 +
The last part is the image size (width x height).
 +
   
 +
Bottom line: an animation like filename-%1-4-800x600 represents an
 +
animation with four frames named filename-0..filename-3 sized 800x600.
 +
 
 +
Data provided:
 +
 
 +
* amdesc
 +
* updatetime
 +
* animatedimage
 +
* copyright
 +
 
 +
== Severe Weather Alerts ==
 +
* swlocation
 +
* alerts
 +
 
 +
== 18 Hour Forecast ==
 +
* 18hrlocation
 +
* time-0 through time-5
 +
* 18icon-0 through 18icon-5
 +
* temp-0 through temp-5
 +
* pop-0 through pop-5
 +
* updatetime
 +
 
 +
<!--
 +
== Tomorrow's Outlook ==
 +
* forecastdate
 +
* tempforecast
 +
* condforecast
 +
* todaypic
 +
* updatetime
 +
* location
 +
-->
 +
 
 +
= Commands =
 +
The below commands are ordered by sequence of being called by MythWeather.
 +
 
 +
== The Version Command (-v) ==
 +
 
 +
This command is called when MythWeather enters the Screen Setup page. It is used to populate a list of available grabbers, for which the user can subsequently create screens. The command returns a comma separated list of the script name, script version, author, and author's email, and output must end with a newline character. If the script version changes from that stored in the database, MythWeather will repopulate the field list and timeouts as detailed below.
  
 
<pre>
 
<pre>
#./bbccurrentxml.pl -T
+
#./bbccurrentxml.pl -v
7200,30
+
BBC-Current-XML,0.2,Stuart Morgan,stuart@tase.co.uk
 
</pre>
 
</pre>
 
  
 
== The Field List Command (-t) ==
 
== The Field List Command (-t) ==
  
All grabber scripts must return a list of available data fields, one per line, when run with the '-t' argument.  
+
MythWeather will next pull a supported field list for all new or updated grabbers. This list is used to determine which screen types the grabber can pull information for. When called, the command must return all supported data fields, one per line.
  
 
<pre>
 
<pre>
Line 42: Line 134:
 
</pre>
 
</pre>
  
 +
== The Timeout Command (-T) ==
 +
 +
MythWeather will next pull a supported field list for all new or updated grabbers. The command returns a comma separated list of information lifetime (minutes), and web response timeout(seconds). These specify how long MythWeather will cache the received data, and how long it will wait before erroring.
 +
 +
<pre>
 +
#./bbccurrentxml.pl -T
 +
7200,30
 +
</pre>
  
 
== The Location Search Command (-l <location>) ==
 
== The Location Search Command (-l <location>) ==
  
All grabber scripts must return a list of possible location matches, one per line, when run with the '-l' argument. The matches are an identifying string to be used with the data string, and a description, separated by a double colon.
+
After information about the grabber is populated by the previous three commands, users will search for locations for a screen, and MythWeather will pass those searches on to one or more grabbers using the '-l' argument. The responses are an identifying string ("id") to be used with the data string, and a description, separated by a double colon, one per line.
  
 
<pre>
 
<pre>
Line 53: Line 153:
 
</pre>
 
</pre>
  
 +
The id is limited by the weathersourcesettings:sourceid field length, currently 64 characters.
  
== The Directory Option (-d) ==
+
== The Data Command (-u <unit system> -d <folder> <location string>) ==
use unknown... for radar image downloads?
+
  
 
+
After a screen with location has been set up, MythWeather will poll the grabber for data. MythWeather will provide the unit system the information should be returned in, and a directory path will full read/write access, which can be used by the script for cache or temporary data. The location string provided by the '-l' command will be the last argument in the call. The unit system will be one of 'SI' or 'ENG'. Only the information should be changed; no units should be provided. The temp directory can be used or ignored, as needed by the script. Data is returned, one value per line, separated from the identifying string by a double colon.
== The Data Command (-u <unit system> <location string>) ==
+
 
+
A grabber script with called without any of the above options must take a unit system, and a location, and return data for each of the fields listed by the '-t' command. The Location will be that provided by the '-l' commands, and the unit system will be one of 'SI' or 'ENG'. Data is returned, one value per line, separated from the identifying string by a double colon.
+
  
 
<pre>
 
<pre>
Line 79: Line 176:
 
</pre>
 
</pre>
  
[[Category:Developer Documentation]]
+
If necessary, some fields are allowed to span multiple lines.  The same data type must be prepended at the beginning of each new line.
 +
 
 +
<pre>
 +
#./nws-alert.pl -u ENG 21015
 +
alerts::SHORT TERM FORECAST
 +
alerts::NATIONAL WEATHER SERVICE WILMINGTON OH
 +
alerts::117 PM EDT SUN MAR 28 2010
 +
alerts::INZ066-073>075-080-KYZ089>096-OHZ070>072-077-078-281902-
 +
alerts::BOONE-BUTLER-CAMPBELL-CARROLL-CLERMONT-CLINTON-DEARBORN-FRANKLIN IN-
 +
alerts::GALLATIN-GRANT-HAMILTON-KENTON-OHIO-OWEN-PENDLETON-RIPLEY-
 +
alerts::SWITZERLAND-WARREN-
 +
alerts::117 PM EDT SUN MAR 28 2010
 +
alerts::.NOW...
 +
alerts::SCATTERED LIGHT SHOWERS WILL CONTINUE TO MOVE TO THE NORTHEAST AND
 +
alerts::ACROSS THE LISTENING AREA THROUGH 3 PM. RAINFALL AMOUNTS WILL BE UP
 +
alerts::ONE TENTH OF AN INCH.
 +
swlocation::Boone,KY
 +
updatetime::Last Updated on Mar 28, 01:27 PM EDT
 +
copyright::NOAA,National Weather Service
 +
</pre>
 +
 
 +
= Type Descriptions =
 +
 
 +
{| cellpadding="4" border="1"
 +
| style="background:silver" | '''cclocation'''
 +
| Descriptive name of location
 +
| Data Type
 +
|-
 +
| style="background:silver" | '''relative_humidity'''
 +
| Percent humidity
 +
| Integer
 +
|-
 +
| style="background:silver" | '''pressure'''
 +
| Barometric pressure
 +
| Float
 +
|-
 +
| style="background:silver" | '''wind_spdgst'''
 +
| Wing speed (gust)
 +
| float
 +
|-
 +
| style="background:silver" | '''wind_dir'''
 +
| Wind direction
 +
| Cardinal, a string like "NNW" or "S"
 +
|-
 +
| style="background:silver" | '''visibility'''
 +
|
 +
| Integer/Range e. g. "10", "1" or "1-4"
 +
|-
 +
| style="background:silver" | '''appt'''
 +
| Apparent temperature, heat index and windchill combo
 +
| Temperature
 +
|-
 +
| style="background:silver" | '''temp'''
 +
| Current Temperature
 +
| Integer Degrees
 +
|-
 +
| style="background:silver" | '''weather'''
 +
| Weather conditions, free text
 +
| String
 +
|-
 +
| style="background:silver" | '''weather_icon'''
 +
| Weather image to show
 +
| filename, as used in the file weather_types.
 +
|-
 +
| style="background:silver" | '''observation_time'''
 +
| Time of last data update
 +
| String
 +
|-
 +
| style="background:silver" | '''copyright'''
 +
| Copyright information needed for ToS compliance
 +
| String
 +
|-
 +
| style="background:silver" | '''3dlocation'''
 +
| Location of forecast
 +
| String
 +
|-
 +
| style="background:silver" | '''6dlocation'''
 +
| Location of forecast
 +
| String
 +
|-
 +
| style="background:silver" | '''date-<n>'''
 +
| Week day number
 +
| Integer, Sunday=0 .. Friday=6
 +
|-
 +
| style="background:silver" | '''icon-<n>'''
 +
| Weather image to show for date-<n>
 +
| filename, as used in the file weather_types.
 +
|-
 +
| style="background:silver" | '''low-<n>'''
 +
| Low temperature forecast for date-<n>
 +
| degrees
 +
|-
 +
| style="background:silver" | '''high-<n>'''
 +
| High temperature forecast for date-<n>
 +
| degrees
 +
|-
 +
| style="background:silver" | '''updatetime'''
 +
| Time of last data update
 +
| String
 +
|-
 +
| style="background:silver" | '''time-<n>'''
 +
| Current hour of forecast
 +
| String
 +
|-
 +
| style="background:silver" | '''18icon-<n>'''
 +
| Weather image to show for time-<n>
 +
| filename
 +
|-
 +
| style="background:silver" | '''temp-<n>'''
 +
| Temperature forecast for time-<n>
 +
| Integer
 +
|-
 +
| style="background:silver" | '''pop-<n>'''
 +
| Precipitation likelihood for time-<n>
 +
| float (percent)
 +
|-
 +
| style="background:silver" | '''swlocation'''
 +
| Descriptive name of location, for weather alerts
 +
| String
 +
|-
 +
| style="background:silver" | '''alerts'''
 +
| Weather alert, can span multiple lines
 +
| String
 +
|-
 +
| style="background:silver" | '''amdesc'''
 +
| Map Description
 +
| String
 +
|-
 +
| style="background:silver" | '''animatedimage'''
 +
| Animated Map Location
 +
| See [[MythWeather Grabber Script Format#Animated Map]]
 +
|-
 +
| style="background:silver" | '''map'''
 +
| Static Map Location
 +
| See [[MythWeather Grabber Script Format#Static Map]]
 +
|}
 +
 
 +
[[Category:Grabber Documentation]]

Revision as of 05:03, 11 May 2010

MythWeather grabber scripts are small executable perl, python, or binary applications which query online sources of weather and return it in a format parseable by MythWeather. This page documents the current format required of the grabber scripts to function.

Data Types

MythWeather has six different types of pages. Grabbers are categorized into these types by the data they specify as capable of providing. Grabbers can seamlessly provide data for multiple pages by making sure to meet all the requirements for each.

Current Conditions

  • cclocation
  • relative_humidity
  • pressure
  • wind_spdgst
  • wind_dir
  • visibility
  • appt
  • temp
  • weather
  • weather_icon
  • observation_time
  • copyright

Three Day Forecast

  • 3dlocation
  • date-0 through date-2
  • icon-0 through icon-2
  • low-0 through low-2
  • high-0 through high-2
  • updatetime

Six Day Forecast

  • 6dlocation
  • date-0 through date-5
  • icon-0 through icon-5
  • high-0 through high-5
  • low-0 through low-5

Static Map

A static map is an image, which is downloaded to a local file by the grabber. The map is a string like /dir1/dir2/filename-600x800. This represents a local file /dir1/dir2/filename with an image sized 600x800. The '-600x800' suffix is not mandatory, if missing the image will be expanded to fill the window.

Data provided:

  • smdesc
  • updatetime
  • map
  • copyright

Animated Map

An animation is typically downloaded as a single file. The grabber splits it into separate files which are stored locally. These files are represented by a single animation string like /dir1/dir2/filename-%1-6-800x600.

The %1 part is replaced with a unique number for each file. So with animation like above there will be files like filename-0, filename-1 etc.

The '6' digit is the number of files. For this example, there will be 6 files named filename-0..filename-5

The last part is the image size (width x height).

Bottom line: an animation like filename-%1-4-800x600 represents an animation with four frames named filename-0..filename-3 sized 800x600.

Data provided:

  • amdesc
  • updatetime
  • animatedimage
  • copyright

Severe Weather Alerts

  • swlocation
  • alerts

18 Hour Forecast

  • 18hrlocation
  • time-0 through time-5
  • 18icon-0 through 18icon-5
  • temp-0 through temp-5
  • pop-0 through pop-5
  • updatetime


Commands

The below commands are ordered by sequence of being called by MythWeather.

The Version Command (-v)

This command is called when MythWeather enters the Screen Setup page. It is used to populate a list of available grabbers, for which the user can subsequently create screens. The command returns a comma separated list of the script name, script version, author, and author's email, and output must end with a newline character. If the script version changes from that stored in the database, MythWeather will repopulate the field list and timeouts as detailed below.

#./bbccurrentxml.pl -v
BBC-Current-XML,0.2,Stuart Morgan,stuart@tase.co.uk

The Field List Command (-t)

MythWeather will next pull a supported field list for all new or updated grabbers. This list is used to determine which screen types the grabber can pull information for. When called, the command must return all supported data fields, one per line.

#./bbccurrentxml.pl -t
cclocation
station_id
copyright
observation_time
weather
temp
relative_humidity
wind_dir
pressure
visibility
weather_icon
appt
wind_spdgst

The Timeout Command (-T)

MythWeather will next pull a supported field list for all new or updated grabbers. The command returns a comma separated list of information lifetime (minutes), and web response timeout(seconds). These specify how long MythWeather will cache the received data, and how long it will wait before erroring.

#./bbccurrentxml.pl -T
7200,30

The Location Search Command (-l <location>)

After information about the grabber is populated by the previous three commands, users will search for locations for a screen, and MythWeather will pass those searches on to one or more grabbers using the '-l' argument. The responses are an identifying string ("id") to be used with the data string, and a description, separated by a double colon, one per line.

#./bbccurrentxml.pl -l Cincinnati
407::Cincinnati, Ohio
3231::Cincinnati/Northern Kentucky International, Kentucky

The id is limited by the weathersourcesettings:sourceid field length, currently 64 characters.

The Data Command (-u <unit system> -d <folder> <location string>)

After a screen with location has been set up, MythWeather will poll the grabber for data. MythWeather will provide the unit system the information should be returned in, and a directory path will full read/write access, which can be used by the script for cache or temporary data. The location string provided by the '-l' command will be the last argument in the call. The unit system will be one of 'SI' or 'ENG'. Only the information should be changed; no units should be provided. The temp directory can be used or ignored, as needed by the script. Data is returned, one value per line, separated from the identifying string by a double colon.

#./bbccurentxml.pl -u ENG 407
appt::NA
copyright::From bbc.co.uk
station_id::407
cclocation::Cincinnati, United States of America
observation_time::Thursday at 13:00 EST
weather::Grey cloud
weather_icon::cloudy.png
temp::43
wind_dir::E
wind_spdgst::9 (NA)
relative_humidity::65
pressure::30.5321117
visibility::10-20

If necessary, some fields are allowed to span multiple lines. The same data type must be prepended at the beginning of each new line.

#./nws-alert.pl -u ENG 21015
alerts::SHORT TERM FORECAST
alerts::NATIONAL WEATHER SERVICE WILMINGTON OH
alerts::117 PM EDT SUN MAR 28 2010
alerts::INZ066-073>075-080-KYZ089>096-OHZ070>072-077-078-281902-
alerts::BOONE-BUTLER-CAMPBELL-CARROLL-CLERMONT-CLINTON-DEARBORN-FRANKLIN IN-
alerts::GALLATIN-GRANT-HAMILTON-KENTON-OHIO-OWEN-PENDLETON-RIPLEY-
alerts::SWITZERLAND-WARREN-
alerts::117 PM EDT SUN MAR 28 2010
alerts::.NOW...
alerts::SCATTERED LIGHT SHOWERS WILL CONTINUE TO MOVE TO THE NORTHEAST AND
alerts::ACROSS THE LISTENING AREA THROUGH 3 PM. RAINFALL AMOUNTS WILL BE UP
alerts::ONE TENTH OF AN INCH.
swlocation::Boone,KY
updatetime::Last Updated on Mar 28, 01:27 PM EDT
copyright::NOAA,National Weather Service

Type Descriptions

cclocation Descriptive name of location Data Type
relative_humidity Percent humidity Integer
pressure Barometric pressure Float
wind_spdgst Wing speed (gust) float
wind_dir Wind direction Cardinal, a string like "NNW" or "S"
visibility Integer/Range e. g. "10", "1" or "1-4"
appt Apparent temperature, heat index and windchill combo Temperature
temp Current Temperature Integer Degrees
weather Weather conditions, free text String
weather_icon Weather image to show filename, as used in the file weather_types.
observation_time Time of last data update String
copyright Copyright information needed for ToS compliance String
3dlocation Location of forecast String
6dlocation Location of forecast String
date-<n> Week day number Integer, Sunday=0 .. Friday=6
icon-<n> Weather image to show for date-<n> filename, as used in the file weather_types.
low-<n> Low temperature forecast for date-<n> degrees
high-<n> High temperature forecast for date-<n> degrees
updatetime Time of last data update String
time-<n> Current hour of forecast String
18icon-<n> Weather image to show for time-<n> filename
temp-<n> Temperature forecast for time-<n> Integer
pop-<n> Precipitation likelihood for time-<n> float (percent)
swlocation Descriptive name of location, for weather alerts String
alerts Weather alert, can span multiple lines String
amdesc Map Description String
animatedimage Animated Map Location See MythWeather Grabber Script Format#Animated Map
map Static Map Location See MythWeather Grabber Script Format#Static Map