Plasma/Public Transport/CreateServiceProviders: Difference between revisions
m (it's->its) |
(Marked this version for translation) |
||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
<translate> | <translate> | ||
== Create a new Service Provider == | == Create a new Service Provider == <!--T:1--> | ||
<!--T:2--> | |||
The names of the files begin with the country code followed by an underscore and a short name (and the extension of course). | The names of the files begin with the country code followed by an underscore and a short name (and the extension of course). | ||
The filename starts with the country code or "international" or "unknown" followed by "_" and a short name of the service provider, e.g. "de_db", "ch_sbb", "sk_atlas", "international_flightstats". The XML file ends with ".xml". | The filename starts with the country code or "international" or "unknown" followed by "_" and a short name of the service provider, e.g. "de_db", "ch_sbb", "sk_atlas", "international_flightstats". The XML file ends with ".xml". | ||
=== The XML file === | === The XML file === <!--T:3--> | ||
<!--T:4--> | |||
The XML file links to the script file that should be used and contains a "raw url", into which the stop name and other information can be inserted. | The XML file links to the script file that should be used and contains a "raw url", into which the stop name and other information can be inserted. | ||
=== The script file === | === The script file === <!--T:5--> | ||
<!--T:6--> | |||
The script file should at least contain a function named "parseTimetable", with one argument. The complete HTML body will be given to the script through that argument. It's then up to the script to parse the document. Here's a list of functions that get called by the PublicTransport data engine to let the script parse a document: | The script file should at least contain a function named "parseTimetable", with one argument. The complete HTML body will be given to the script through that argument. It's then up to the script to parse the document. Here's a list of functions that get called by the PublicTransport data engine to let the script parse a document: | ||
<!--T:7--> | |||
*'''parseTimetable( html )''' (Used to parse departure/arrival documents) | *'''parseTimetable( html )''' (Used to parse departure/arrival documents) | ||
*'''parseJourneys( html )''' (Used to parse journey documents) | *'''parseJourneys( html )''' (Used to parse journey documents) | ||
Line 22: | Line 26: | ||
==== Helper Functions ==== | ==== Helper Functions ==== <!--T:8--> | ||
<!--T:9--> | |||
There is a helper object named "helper" which can be used by the script. It has these functions: | There is a helper object named "helper" which can be used by the script. It has these functions: | ||
<!--T:10--> | |||
*'''trim( string )''' (Removes '&nbsp;' from the beginning and the end of the given string) | *'''trim( string )''' (Removes '&nbsp;' from the beginning and the end of the given string) | ||
*'''stripTags( string )''' (Removes all tags from the given string, ie. removing <...> or </...>) | *'''stripTags( string )''' (Removes all tags from the given string, ie. removing <...> or </...>) | ||
Line 38: | Line 44: | ||
==== Add Parsed Departures to the Result Set ==== | ==== Add Parsed Departures to the Result Set ==== <!--T:11--> | ||
<!--T:12--> | |||
There is an object named "timetableData" given to the script. To add a parsed departure to the result set do something like this: | There is an object named "timetableData" given to the script. To add a parsed departure to the result set do something like this: | ||
<!--T:13--> | |||
{{Input|1= | {{Input|1= | ||
// Add departure | // Add departure | ||
Line 52: | Line 60: | ||
result.addData( timetableData );}} | result.addData( timetableData );}} | ||
<!--T:14--> | |||
This will add a departure of the tram line "N6", departing at 1:30 with the target "Bremen Hbf". | This will add a departure of the tram line "N6", departing at 1:30 with the target "Bremen Hbf". | ||
==== Information Types ==== | ==== Information Types ==== <!--T:15--> | ||
<!--T:16--> | |||
Here is a list of all information types you can add to the timetableData object for a departure/arrival/journey: | Here is a list of all information types you can add to the timetableData object for a departure/arrival/journey: | ||
<!--T:17--> | |||
*'''DepartureDate''' (The date of the departure) | *'''DepartureDate''' (The date of the departure) | ||
*'''DepartureHour''' ('''Mandatory for departures/arrivals/journeys''', the hour of the departure) | *'''DepartureHour''' ('''Mandatory for departures/arrivals/journeys''', the hour of the departure) | ||
Line 93: | Line 104: | ||
*'''RouteTimesArrivalDelay''' (A list of delays in minutes for each arrival time of a route (RouteTimesArrival)) | *'''RouteTimesArrivalDelay''' (A list of delays in minutes for each arrival time of a route (RouteTimesArrival)) | ||
<!--T:18--> | |||
''These information elements only apply to journeys:'' | ''These information elements only apply to journeys:'' | ||
<!--T:19--> | |||
*'''Duration''' (The duration of a journey) | *'''Duration''' (The duration of a journey) | ||
*'''StartStopName''' (The name of the starting stop of a journey) | *'''StartStopName''' (The name of the starting stop of a journey) | ||
Line 107: | Line 120: | ||
*'''Pricing''' (Information about the pricing of a journey) | *'''Pricing''' (Information about the pricing of a journey) | ||
<!--T:20--> | |||
''These information elements only apply to stop suggestions: '' | ''These information elements only apply to stop suggestions: '' | ||
<!--T:21--> | |||
*'''StopName''' ('''Mandatory for stop suggestions''', The name of a stop / station) | *'''StopName''' ('''Mandatory for stop suggestions''', The name of a stop / station) | ||
*'''StopID''' (The ID of a stop / station) | *'''StopID''' (The ID of a stop / station) | ||
*'''StopWeight''' (The weight of a stop suggestion) | *'''StopWeight''' (The weight of a stop suggestion) | ||
<!--T:22--> | |||
{{Info|1=There will be templates for an XML and a script file later. Until then, you can check out the existing service providers.}} | {{Info|1=There will be templates for an XML and a script file later. Until then, you can check out the existing service providers.}} | ||
<!--T:23--> | |||
[[Category:Plasma]] | [[Category:Plasma]] | ||
[[Category:Widgets]] | [[Category:Widgets]] |
Revision as of 11:18, 29 December 2010
Create a new Service Provider
The names of the files begin with the country code followed by an underscore and a short name (and the extension of course). The filename starts with the country code or "international" or "unknown" followed by "_" and a short name of the service provider, e.g. "de_db", "ch_sbb", "sk_atlas", "international_flightstats". The XML file ends with ".xml".
The XML file
The XML file links to the script file that should be used and contains a "raw url", into which the stop name and other information can be inserted.
The script file
The script file should at least contain a function named "parseTimetable", with one argument. The complete HTML body will be given to the script through that argument. It's then up to the script to parse the document. Here's a list of functions that get called by the PublicTransport data engine to let the script parse a document:
- parseTimetable( html ) (Used to parse departure/arrival documents)
- parseJourneys( html ) (Used to parse journey documents)
- parsePossibleStops( html ) (Used to parse stop suggestion documents)
Helper Functions
There is a helper object named "helper" which can be used by the script. It has these functions:
- trim( string ) (Removes ' ' from the beginning and the end of the given string)
- stripTags( string ) (Removes all tags from the given string, ie. removing <...> or </...>)
- camelCase( string ) (The first character of each word will be upper case, all others lower case)
- extractBlock( string, beginString, endString ) (Returns the string between the first occurance of beginString and the first occurance of endString, or an empty string if beginString or endString couldn't be found in string. For example extractBlock("<b>Bold Text</b>", "<b>", "</b>") returns "Bold Text")
- matchTime( string, formatString ) (Searches for a time string of the given format, eg. "hh:mm" and returns a list with two integers, the hour and the minute)
- formatTime( hour, minute, formatString ) (Formats the given time using the given formatString)
- duration( sTime1, sTime2, formatString ) (Returns the duration in minutes from sTime1 to sTime2, which are time strings in the given format)
- addMinsToTime( sTime, minsToAdd, formatString ) (Parses the given time using the given formatString, adds minsToAdd minutes and format it again using formatString)
- splitSkipEmptyParts( string, separator ) (Splits the given string using the given separator, while skipping empty parts)
Add Parsed Departures to the Result Set
There is an object named "timetableData" given to the script. To add a parsed departure to the result set do something like this:
// Add departure timetableData.clear(); timetableData.set( 'TransportLine', 'N6' ); timetableData.set( 'TypeOfVehicle', 'STR' ); timetableData.set( 'Target', 'Bremen Hbf' ); timetableData.set( 'DepartureHour', 1 ); timetableData.set( 'DepartureMinute', 30 ); result.addData( timetableData );
This will add a departure of the tram line "N6", departing at 1:30 with the target "Bremen Hbf".
Information Types
Here is a list of all information types you can add to the timetableData object for a departure/arrival/journey:
- DepartureDate (The date of the departure)
- DepartureHour (Mandatory for departures/arrivals/journeys, the hour of the departure)
- DepartureMinute (Mandatory for departures/arrivals/journeys, the minute of the departure)
- TransportLine (Mandatory for departures/arrivals, The name of the public transport line, e.g. "4", "6S", "S 5", "RB 24122")
- Target (Mandatory for departures/arrivals, The target of a journey / of a public transport line)
- TypeOfVehicle (The type of vehicle)
- FlightNumber (Same as TransportLine, used for flights)
- Platform (The platform at which the vehicle departs/arrives)
- Delay (The delay of a public transport vehicle)
- DelayReason (The reason of a delay)
- JourneyNews (Can contain delay / delay reason / other news)
- JourneyNewsOther (Other news (not delay / delay reason))
- JourneyNewsLink (Contains a link to an html page with journey news. The url of the accessor is prepended, if a relative path has been matched (starting with "/"))
- DepartureHourPrognosis (The prognosis for the departure hour, which is the departure hour plus the delay)
- DepartureMinutePrognosis (The prognosis for the departure minute, which is the departure minute plus the delay)
- Operator (The company that is responsible for the journey)
- DepartureAMorPM (Used to match the string "am" or "pm" for the departure time)
- DepartureAMorPMPrognosis (Used to match the string "am" or "pm" for the prognosis departure time)
- ArrivalAMorPM (Used to match the string "am" or "pm" for the arrival time)
- Status (The current status of the departure/arrival. Currently only used for planes)
- DepartureYear (The year of the departure, to be used when the year is separated from the date)
- RouteStops (A list of stops of the departure/arrival to its destination stop or a list of stops of the journey from its start to its destination stop. If RouteStops and RouteTimes are both set, they should contain the same number of elements. And elements with equal indices should be associated (the times at which the vehicle is at the stops). For journeys RouteTimesDeparture and RouteTimesArrival should be used instead of RouteTimes)
- RouteTimes (A list of times of the departure/arrival to its destination stop. If RouteStops and RouteTimes are both set, they should contain the same number of elements. And elements with equal indices should be associated (the times at which the vehicle is at the stops))
- RouteTimesDeparture (A list of departure times of the journey. If RouteStops and RouteTimesDeparture are both set, the latter should contain one elements less (because the last stop has no departure, only an arrival time). Elements with equal indices should be associated (the times at which the vehicle departs from the stops))
- RouteTimesArrival (A list of arrival times of the journey. If RouteStops and RouteTimesArrival are both set, the latter should contain one elements less (because the first stop has no arrival, only a departure time). Elements with equal indices should be associated (the times at which the vehicle arrives at the stops))
- RouteExactStops (The number of exact route stops. The route stop list isn't complete from the last exact route stop)
- RouteTypesOfVehicles (The types of vehicles used for each "sub-journey" of a journey)
- RouteTransportLines (The transport lines used for each "sub-journey" of a journey)
- RoutePlatformsDeparture (The platforms of departures used for each "sub-journey" of a journey)
- RoutePlatformsArrival (The platforms of arrivals used for each "sub-journey" of a journey)
- RouteTimesDepartureDelay (A list of delays in minutes for each departure time of a route (RouteTimesDeparture))
- RouteTimesArrivalDelay (A list of delays in minutes for each arrival time of a route (RouteTimesArrival))
These information elements only apply to journeys:
- Duration (The duration of a journey)
- StartStopName (The name of the starting stop of a journey)
- StartStopID (The ID of the starting stop of a journey)
- TargetStopName (The name of the target stop of a journey)
- TargetStopID (The ID of the target stop of a journey)
- ArrivalDate (The date of the arrival)
- ArrivalHour (Mandatory for journeys, The hour of the arrival)
- ArrivalMinute (Mandatory for journeys, The minute of the arrival)
- Changes (The number of changes between different vehicles in a journey)
- TypesOfVehicleInJourney (A list of vehicle types used in a journey)
- Pricing (Information about the pricing of a journey)
These information elements only apply to stop suggestions:
- StopName (Mandatory for stop suggestions, The name of a stop / station)
- StopID (The ID of a stop / station)
- StopWeight (The weight of a stop suggestion)