feed_example.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-FileCopyrightText: Adam Evyčędo
  2. //
  3. // SPDX-License-Identifier: AGPL-3.0-or-later
  4. /*
  5. TODO(1)
  6. First choose an ID and struct name for the network You add.
  7. As a guideline, the ID should be in format {locality}_{operator} and structure should be named {locality}{operator}.
  8. In this example, we’ll be using a hipotetical network in Gravity Falls operated by Cipher Bus Transport, so the ID will be gravityfalls_cbt and the structure will be named GravityFallsCbt.
  9. Finally copy this file to a new one named {ID}.go, i.e. gravityfalls_cbt.go
  10. */
  11. package traffic
  12. import (
  13. "net/http"
  14. "time"
  15. "golang.org/x/text/transform"
  16. )
  17. /*
  18. TODO(2)
  19. Define the scructure with http.Client and other fields as needed
  20. */
  21. type GravityFallsCbt struct {
  22. client http.Client
  23. }
  24. /*
  25. TODO(3)
  26. Fill in the IANA time zone for the operator.
  27. It is only used to determine validity of published timetables.
  28. For Gravity Falls, Oregon, the time zone will be that of Los_Angeles
  29. */
  30. func (GravityFallsCbt) getTimezone() *time.Location {
  31. l, _ := time.LoadLocation("America/Los_Angeles")
  32. return l
  33. }
  34. /*
  35. TODO(4)
  36. If the operator publishes a file with description of vehicles used, then download, parse and convert it to list of Vehicle structures.
  37. Otherwise, leave this empty return.
  38. */
  39. func (g GravityFallsCbt) ConvertVehicles() ([]Vehicle, error) {
  40. return []Vehicle{}, nil
  41. }
  42. /*
  43. TODO(5)
  44. Here, return list of available timetables.
  45. Use the given timezone to create full valid-since and valid-till date-times.
  46. If it’s not known since when the timetable is valid, use zero time; similarly, if end of validity is not known, use 9999-12-31.
  47. As an example, there may exist an operator that publishes timetable under one address that is guaranteed to be valid at the time of donwloading; such timetable would be valid here from year 0 to 9999.
  48. */
  49. func (z GravityFallsCbt) GetVersions(_ time.Time, timezone *time.Location) ([]Version, error) {
  50. return []Version{}, nil
  51. }
  52. /*
  53. TODO(6)
  54. Return the chosen ID of the network.
  55. */
  56. func (GravityFallsCbt) String() string {
  57. return "gravityfalls_cbt"
  58. }
  59. /*
  60. TODO(7)
  61. If the operator publishes GTFS-RT feeds for the timetables, fill the returned map with respective feeds, or with the same one if it contains multiple types of updates.
  62. */
  63. func (GravityFallsCbt) RealtimeFeeds() map[RealtimeFeedType]string {
  64. return map[RealtimeFeedType]string{
  65. TRIP_UPDATES: "https://cipherbustransport.oregon.co.us/gtfsrt/all.pb",
  66. VEHICLE_POSITIONS: "https://cipherbustransport.oregon.co.us/gtfsrt/all.pb",
  67. ALERTS: "https://cipherbustransport.oregon.co.us/gtfsrt/alerts.pb",
  68. }
  69. }
  70. /*
  71. TODO(8)
  72. If the operator uses a custom API and not GTFS-RT for updates, vehicles positions, or alerts, create a Lua script in file traffic/realtime_lua/{updates_type}_{ID}.lua—where {updates_type} is one of ‘updates’, ‘vehicles’, ‘alerts’—which can serve as a client of that API.
  73. Do not create such file if GTFS-RT feed for this type of update is available.
  74. More information can be found in TRAFFIC documentation.
  75. */
  76. /*
  77. TODO(9)
  78. Return a Transformer or a chain of them, which can replace non-ASCII letters in lines’ and stops’ names with their ASCII counterpart; e.g. for Norwegian å -> aa, for German ä -> ae, for French á -> a.
  79. If such Transformer is not available, add a new one in transformer package.
  80. */
  81. func (GravityFallsCbt) Transformer() transform.Transformer {
  82. return transform.Nop
  83. }
  84. /*
  85. TODO(10)
  86. Return full, public-facing name of the network.
  87. */
  88. func (GravityFallsCbt) Name() string {
  89. return "Gravity Falls CBT"
  90. }
  91. /*
  92. TODO(11)
  93. Return flags which setup converter behaviour:
  94. * Headsigns are taken from trips or from last stop,
  95. * Which field in GTFS stops.txt file is stable across versions,
  96. * How to unambiguously format a stop name,
  97. * How to unambiguously format a line name.
  98. */
  99. func (GravityFallsCbt) Flags() FeedFlags {
  100. return FeedFlags{
  101. Headsign: HeadsignTripHeadsing,
  102. StopIdFormat: "{{stop_code}}",
  103. StopName: "{{stop_name}} [{{stop_code}}]",
  104. LineName: "{{route_short_name}}",
  105. }
  106. }
  107. /*
  108. TODO(12)
  109. Correct all errors in GTFS file.
  110. Everything that is not correct acording to the GTFS documentation is considered an error.
  111. This function has access to unzipped GTFS file and can operate on files at `path/specific_file.txt`
  112. */
  113. func (GravityFallsCbt) FeedPrepareZip(path string) error {
  114. return nil
  115. }
  116. /*
  117. TODO(13)
  118. If QR codes are available on stops with address that leads to realtime departures, return host, location of stop identifier and query param or regex to extract the identifier.
  119. */
  120. func (GravityFallsCbt) QRInfo() (string, QRLocation, string) {
  121. return "", QRLocationNone, ""
  122. }
  123. /*
  124. TODO(14)
  125. Add description and attribution to strings in `translations/messages.en.yml` and any other languages if You can.
  126. */
  127. /*
  128. TODO(15)
  129. Add the structure in RegisterFeeds function in `traffic/feeds.go`
  130. */