Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # hafas-client
  2. **A client for the "mobile APIs" of [HAFAS](https://de.wikipedia.org/wiki/HAFAS) public transport management systems**.
  3. [![npm version](https://img.shields.io/npm/v/hafas-client.svg)](https://www.npmjs.com/package/hafas-client)
  4. [![build status](https://img.shields.io/github/workflow/status/public-transport/hafas-client/test/5)](https://github.com/public-transport/hafas-client/actions?query=branch%3A5)
  5. ![ISC-licensed](https://img.shields.io/github/license/public-transport/hafas-client.svg)
  6. [![support Jannis via GitHub Sponsors](https://img.shields.io/badge/support%20Jannis-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)
  7. [![chat with Jannis on Twitter](https://img.shields.io/badge/chat%20with%20Jannis-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)
  8. ## Background
  9. [A company called HaCon](https://hacon.de) sells [a public transport management system called HAFAS](https://de.wikipedia.org/wiki/HAFAS) to public transport authorities and providers, mostly in Europe. It provides routing and departure information to their customers.
  10. Most customers get their own, **separate HAFAS deployments**; They all use the same terminology and API calls, but have slightly different versions, configurations and sets of enabled features. Using [built-in endpoint-specific customisations](p/readme.md), **`hafas-client` abstracts most of these differences away, and supports additional features in some cases**. Check the [list of supported networks/endpoints](p/readme.md#built-in-profiles) for more info.
  11. *Note:* Currently, **`hafas-client` only supports "mobile API" endpoints**, which are designed for and used by the respective official mobile app(s); These endpoints almost always have `mgate.exe` in the URL. This library *does not* support "open API" endpoints (often they have `rest-proxy` or `openapi` in the URL) yet, but [#134](https://github.com/public-transport/hafas-client/pull/134) contains work in progress.
  12. Strictly speaking, permission is necessary to use this library with a HAFAS "mobile" endpoint. It merely tries to remove the *technical* barrier of accessing the data, in order to kick-start an ecosystem or apps and services that will eventually rely on [*openly available* data](https://opendatahandbook.org/solutions/en/Public-Transport-Data/).
  13. ## Supported networks/endpoints
  14. `hafas-client` has [built-in support for many public transportation networks](p/readme.md).
  15. There are also libraries that use `hafas-client` and pass their own profile in:
  16. HAFAS endpoint | library
  17. ---------------|--------
  18. [Betriebsstellen & disturbances in the German rail network](https://strecken.info/) | [`db-netz-hafas`](https://github.com/derhuerst/db-netz-hafas)
  19. ## Installing
  20. ```shell
  21. npm install hafas-client
  22. ```
  23. ### with [react-native](https://facebook.github.io/react-native/)
  24. `hafas-client` as well its dependencies use [Node-builtin modules](https://nodejs.org/dist/latest/docs/api/) and [Node globals](https://nodejs.org/api/globals.html). To be able to use it within react-native, follow [the instructions at `node-libs-react-native`](https://github.com/parshap/node-libs-react-native/blob/master/README.md#usage).
  25. ## Usage
  26. Pick the [profile](p/readme.md) for the HAFAS endpoint covering the area you want to get data for. Pass the profile and a descriptive name for your program into the `createClient` function:
  27. ```js
  28. const createClient = require('hafas-client')
  29. const dbProfile = require('hafas-client/p/db')
  30. // create a client with the Deutsche Bahn profile
  31. const client = createClient(dbProfile, 'my-awesome-program')
  32. ```
  33. You can now use `client` to query the HAFAS endpoint configured in the [`db` profile](p/db):
  34. ```js
  35. // Berlin Jungfernheide to München Hbf
  36. const res = await client.journeys('8011167', '8000261', {results: 1})
  37. console.log(res)
  38. ```
  39. `journeys()` returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/promise) that will resolve with an object with an array `journeys` that contains one [*Friendly Public Transport Format* (*FPTF*) v2 draft `journey`](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md#journey).
  40. ```js
  41. {
  42. journeys: [ {
  43. origin: {
  44. type: 'station',
  45. id: '8089100',
  46. name: 'Berlin Jungfernheide (S)',
  47. location: { /* … */ },
  48. products: { /* … */ }
  49. },
  50. departure: '2017-12-19T17:05:30+01:00',
  51. plannedDeparture: '2017-12-19T17:05:00+01:00',
  52. departureDelay: 30,
  53. departurePlatform: '5',
  54. plannedDeparturePlatform: '5',
  55. destination: {
  56. type: 'station',
  57. id: '8000261',
  58. name: 'München Hbf',
  59. location: { /* … */ },
  60. products: { /* … */ }
  61. },
  62. arrival: '2017-12-19T22:44:00+01:00',
  63. plannedArrival: '2017-12-19T22:45:00+01:00',
  64. arrivalDelay: -60,
  65. arrivalPlatform: '11A',
  66. plannedArrivalPlatform: '13',
  67. legs: [ {
  68. id: '1|100067|48|81|17122017',
  69. line: {
  70. type: 'line',
  71. id: '41172',
  72. name: 'S 41',
  73. public: true,
  74. mode: 'train',
  75. product: 'suburban',
  76. operator: {
  77. type: 'operator',
  78. id: 's-bahn-berlin-gmbh',
  79. name: 'S-Bahn Berlin GmbH'
  80. }
  81. },
  82. direction: 'Ringbahn ->',
  83. origin: {
  84. type: 'station',
  85. id: '8089100',
  86. name: 'Berlin Jungfernheide (S)',
  87. location: {
  88. type: 'location',
  89. latitude: 52.530291,
  90. longitude: 13.299451
  91. },
  92. products: { /* … */ }
  93. },
  94. departure: '2017-12-19T17:05:30+01:00',
  95. plannedDeparture: '2017-12-19T17:05:00+01:00',
  96. departureDelay: 30,
  97. departurePlatform: '5',
  98. plannedDeparturePlatform: '5',
  99. destination: {
  100. type: 'station',
  101. id: '8089118',
  102. name: 'Berlin Beusselstraße'
  103. // …
  104. },
  105. arrival: '2017-12-19T17:08:00+01:00',
  106. plannedArrival: '2017-12-19T17:08:00+01:00',
  107. arrivalDelay: null,
  108. arrivalPlatform: '2a-b',
  109. plannedArrivalPlatform: '1'
  110. },
  111. /* more legs… */
  112. {
  113. walking: true,
  114. public: true,
  115. origin: {
  116. type: 'station',
  117. id: '730749',
  118. name: 'Berlin Hauptbahnhof (S+U), Berlin'
  119. // …
  120. },
  121. plannedDeparture: '2017-12-19T17:25:00+01:00',
  122. prognosedDeparture: null,
  123. departureDelay: null,
  124. destination: {
  125. type: 'station',
  126. id: '8098160',
  127. name: 'Berlin Hbf (tief)'
  128. // …
  129. },
  130. arrival: '2017-12-19T17:33:00+01:00',
  131. plannedArrival: '2017-12-19T17:33:00+01:00',
  132. arrivalDelay: null
  133. }, {
  134. id: '1|70906|0|81|17122017',
  135. line: { /* … */ },
  136. direction: 'München Hbf',
  137. origin: {
  138. type: 'station',
  139. id: '8098160',
  140. name: 'Berlin Hbf (tief)'
  141. // …
  142. },
  143. departure: '2017-12-19T17:35:00+01:00',
  144. plannedDeparture: '2017-12-19T17:37:00+01:00',
  145. departureDelay: -120,
  146. departurePlatform: '1',
  147. plannedDeparturePlatform: '1',
  148. destination: {
  149. type: 'station',
  150. id: '8000261',
  151. name: 'München Hbf',
  152. // …
  153. },
  154. arrival: '2017-12-19T22:44:00+01:00',
  155. plannedArrival: '2017-12-19T22:45:00+01:00',
  156. arrivalDelay: -60,
  157. arrivalPlatform: '11A',
  158. plannedArrivalPlatform: '13'
  159. } ],
  160. price: {
  161. amount: null,
  162. hint: 'No pricing information available.'
  163. }
  164. // …
  165. } ]
  166. // …
  167. }
  168. ```
  169. Each [profile](p/readme.md) has more detailed example code.
  170. ### in the browser
  171. While `hafas-client` itself should work in the browser via a bundler like [Webpack](https://webpack.js.org), most HAFAS API endpoints don't enable [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing), so you won't be able query them directly.
  172. ## API
  173. [API documentation](docs/readme.md)
  174. ## Related Projects
  175. - [`*.transport.rest`](https://transport.rest/) – Public APIs wrapping some HAFAS endpoints.
  176. - [`BahnhofsAbfahrten`](https://github.com/marudor/BahnhofsAbfahrten) a.k.a. [`marudor.de`](https://marudor.de/) – A very detailed public transport website for Germany. Uses HAFAS underneath, [has an API](https://docs.marudor.de).
  177. - [`public-transport-enabler`](https://github.com/schildbach/public-transport-enabler) – Java equivalent to `hafas-client`, with support for more types of public transport APIs; Used by [Öffi](https://play.google.com/store/apps/details?id=de.schildbach.oeffi) & [Transportr](https://transportr.app).
  178. - [`TripKit`](https://github.com/alexander-albers/tripkit) – Swift equivalent to `hafas-client`, with support for more types of public transport APIs; Used by [ÖPNV Navigator](https://apps.apple.com/de/app/öpnv-navigator/id1239908782).
  179. - [`pyhafas`](https://github.com/n0emis/pyhafas) – Python equivalent to `hafas-client`, with support for more types of public transport APIs.
  180. - [*Friendly Public Transport Format*](https://github.com/public-transport/friendly-public-transport-format#friendly-public-transport-format-fptf) – A format for APIs, libraries and datasets containing and working with public transport data.
  181. - [`observe-hafas-client`](https://github.com/public-transport/observe-hafas-client) – Observe all departures/arrivals/etc. returned by `hafas-client`.
  182. - [`cached-hafas-client`](https://github.com/public-transport/cached-hafas-client) – Pass in a `hafas-client` instance, cache data from it.
  183. - [`hafas-client-rpc`](https://github.com/derhuerst/hafas-client-rpc) – Make JSON-RPC calls to `hafas-client` via WebSockets & stdio.
  184. - [`hafas-client-health-check`](https://github.com/public-transport/hafas-client-health-check) – Check if a `hafas-client` instance and its endpoint work.
  185. - [`hafas-rest-api`](https://github.com/public-transport/hafas-rest-api#hafas-rest-api) – Expose a HAFAS client via an HTTP REST API.
  186. - [List of european long-distance transport operators, available API endpoints, GTFS feeds and client modules.](https://github.com/public-transport/european-transport-operators)
  187. - [Collection of european transport JavaScript modules.](https://github.com/public-transport/european-transport-modules)
  188. - [`hafas-find-stations`](https://github.com/derhuerst/hafas-find-stations#hafas-find-stations) – Given a HAFAS client, find all stations in a bounding box.
  189. - [`hafas-collect-departures-at`](https://github.com/public-transport/hafas-collect-departures-at#hafas-collect-departures-at) – Utility to collect departures, using any HAFAS client.
  190. - [`find-hafas-data-in-another-hafas`](https://github.com/derhuerst/find-hafas-data-in-another-hafas#find-hafas-data-in-another-hafas) – Find data from one HAFAS endpoint in the data of another HAFAS endpoint.
  191. - [`hafas-monitor-trips`](https://github.com/derhuerst/hafas-monitor-trips#hafas-monitor-trips) – Using a HAFAS client, watch all trips in a bounding box.
  192. - [`hafas-monitor-departures`](https://github.com/derhuerst/hafas-monitor-departures#hafas-monitor-departures) – Pass in a HAFAS client, fetch all departures at any set of stations.
  193. - [`hafas-record-delays`](https://github.com/derhuerst/hafas-record-delays#hafas-record-delays) – Record delays from `hafas-monitor-departures` into a LevelDB.
  194. - [`hafas-monitor-journeys`](https://github.com/derhuerst/hafas-monitor-journeys) – Use `hafas-client` to monitor journeys from A to B.
  195. - [`hafas-discover-stations`](https://github.com/derhuerst/hafas-discover-stations#hafas-discover-stations) – Pass in a HAFAS client, discover stations by querying departures.
  196. - [`hafas-estimate-station-weight`](https://github.com/derhuerst/hafas-estimate-station-weight#hafas-estimate-station-weight) – Pass in a HAFAS client, estimate the importance of a station.
  197. More related libraries can be found [via the npm package index](https://www.npmjs.com/search?q=hafas).
  198. ## Contributing
  199. If you **have a question**, **found a bug** or want to **propose a feature**, please [open an Issue](https://github.com/public-transport/hafas-client/issues).
  200. This project needs help! Check the [list of "help wanted" Issues](https://github.com/public-transport/hafas-client/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
  201. If you're contributing code, please read the [contribution guidelines](contributing.md).