{"id":17367443,"url":"https://github.com/juliuste/sncf","last_synced_at":"2025-04-08T03:34:56.489Z","repository":{"id":57364656,"uuid":"76692362","full_name":"juliuste/sncf","owner":"juliuste","description":"SNCF API client","archived":false,"fork":false,"pushed_at":"2020-06-01T07:39:50.000Z","size":167,"stargazers_count":27,"open_issues_count":18,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-17T02:54:55.797Z","etag":null,"topics":["library","public-transport","railway"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliuste.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-16T23:24:29.000Z","updated_at":"2024-03-28T14:02:05.000Z","dependencies_parsed_at":"2022-09-13T21:01:05.933Z","dependency_job_id":null,"html_url":"https://github.com/juliuste/sncf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fsncf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fsncf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fsncf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fsncf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliuste","download_url":"https://codeload.github.com/juliuste/sncf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223300901,"owners_count":17122711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","public-transport","railway"],"created_at":"2024-10-15T22:41:27.075Z","updated_at":"2024-11-06T07:33:08.171Z","avatar_url":"https://github.com/juliuste.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sncf\n\nJavaScript client for the [sncf](https://www.voyages-sncf.com/) API. Complies with the [friendly public transport format](https://github.com/public-transport/friendly-public-transport-format). Inofficial, using endpoints by *SNCF*. Ask them for permission before using this module in production. *Work in progress.*\n\n[![npm version](https://img.shields.io/npm/v/sncf.svg)](https://www.npmjs.com/package/sncf)\n[![Build Status](https://travis-ci.org/juliuste/sncf.svg?branch=master)](https://travis-ci.org/juliuste/sncf)\n[![Greenkeeper badge](https://badges.greenkeeper.io/juliuste/sncf.svg)](https://greenkeeper.io/)\n[![dependency status](https://img.shields.io/david/juliuste/sncf.svg)](https://david-dm.org/juliuste/sncf)\n[![license](https://img.shields.io/github/license/juliuste/sncf.svg?style=flat)](LICENSE)\n[![fptf version](https://fptf.badges.juliustens.eu/badge/juliuste/sncf)](https://fptf.badges.juliustens.eu/link/juliuste/sncf)\n[![chat on gitter](https://badges.gitter.im/juliuste.svg)](https://gitter.im/juliuste)\n\n## Installation\n\n```shell\nnpm install --save sncf\n```\n\n## Usage\n\nThis package contains data in the [*Friendly Public Transport Format*](https://github.com/public-transport/friendly-public-transport-format).\n\n### `stations(query)`\n\nUsing `sncf.stations`, you can search train stations operated by SNCF.\n\n```js\nconst stations = require('sncf').stations\n\nstations(\"Montpellier\")\n.then(console.log)\n.catch(console.error)\n```\n\nReturns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/promise) that will resolve in an array of `station`s in the [*Friendly Public Transport Format*](https://github.com/public-transport/friendly-public-transport-format) which looks as follows:\n\n```js\n[\n    {\n        type: \"station\",\n        id: \"FRMPL\",\n        name: \"Montpellier Saint-Roch (Occitanie)\"\n    }\n    // …\n]\n```\n\n### `journeys(origin, destination, date = new Date(), opt = {})`\n\nUsing `sncf.journeys`, you can get directions and prices for routes from A to B. `origin` and `destination` can be station `id`s or FPTF `station` objects.\n\n```js\nconst journeys = require('sncf').journeys\n\nconst frankfurt = 'DEFRA'\nconst lyon = {type: 'station', id: 'FRLYS'}\n\njourneys(frankfurt, lyon, new Date(), {duration: 24*60*60*1000})\n.then(console.log)\n.catch(console.error)\n```\n\n`defaults`, partially overridden by the `opt` parameter, looks like this:\n\n```js\nconst defaults = {\n    duration: 6*60*60*1000  // searches for journeys in the next 6 hours starting at 'date' (parameter). Warning: Spawns multiple requests, may take a couple of seconds for longer durations!\n    direct: false,  // direct connections only\n    class: 2, // one of [1, 2]\n\tvia: null, // station code or object\n\tlanguage: 'fr',\n\tcountry: 'FR', // probably influences price currency (?)\n}\n```\n\nReturns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/promise) that will resolve with an array of `journey`s in the [*Friendly Public Transport Format*](https://github.com/public-transport/friendly-public-transport-format) which looks as follows. Please note that the results are not fully spec-compatible since `arrival` and `departure` Date strings don't contain the station timezones, because the API doesn't provide this information.\n\n```js\n[\n    {\n        type: \"journey\",\n        id: \"3c9cb584-c16a-43ca-84fa-f89a610e9d82\",\n        legs: [\n            {\n                origin: \"DEFRS\",\n                destination: \"CHAJP\",\n                departure: \"2018-03-27T04:02:00+01:00\",\n                arrival: \"2018-03-27T07:20:00+01:00\",\n                line: {\n                    type: \"line\",\n                    id: \"401\",\n                    name: \"Train 401\",\n                    mode: \"train\",\n                    vehicleType: \"ONL\",\n                    services: [],\n                    operator: \"OE\"\n                },\n                operator: \"OE\",\n                schedule: \"defrs-2018-03-27t04-02-00-01-00-chajp-2018-03-27t07-20-00-01-00\"\n            }\n            // …\n        ],\n        price: {\n            amount: 86,\n            currency: \"EUR\",\n            fares: [\n                {\n                    price: {\n                        amount: 121,\n                        currency: \"EUR\"\n                    },\n                    model: \"SEMIFLEX\",\n                    appliedDiscount: 0,\n                    passengers: [\n                        {\n                            clientId: \"0\",\n                            travelerId: null,\n                            price: 121,\n                            age: \"ADULT\",\n                            fidelityCard: \"NONE\",\n                            fidelityPoints: null,\n                            promoCodeType: null,\n                            fareInformations: [\n                                {\n                                    fareName: \"TARIF NORMAL ADULTE\",\n                                    fareCondition: \"Billet remboursable sans frais jusqu'à 15 jours avant le départ, avec une pénalité de 50% à partir de 14 jours et jusqu'à 1 jours avant le départ. Billet non remboursable à partir de 1 jours avant le départ.\",\n                                    fareCode: \"AFAD\",\n                                    fareSpecificRule: null,\n                                    fareSequence: null,\n                                    cosLevel: null,\n                                    returnMandatory: false,\n                                    passengerType: \"PT00AD\",\n                                    classOfService: \"B\",\n                                    segmentId: 6,\n                                    passengerClientId: \"0\",\n                                    promoCodeApplied: false,\n                                    fixedPriceCuiQuotation: false,\n                                    fakeFare: false\n                                }\n                                // …\n                            ],\n                            passengerType: \"HUMAN\",\n                            encartedPrems: false,\n                            specificSeatRequired: true,\n                            hanInformation: null,\n                            promoCodeApplied: false\n                        }\n                    ],\n                    animals: [],\n                    bookingFee: {\n                        amount: 5,\n                        type: \"FDD\"\n                    },\n                    bicycle: false,\n                    placementOptions: true\n                }\n                // …\n            ]\n        },\n        isRealTime: false\n    }\n    // …\n]\n```\n\n----\n\n## See also\n\n- [FPTF](https://github.com/public-transport/friendly-public-transport-format) - \"Friendly public transport format\"\n- [FPTF-modules](https://github.com/public-transport/friendly-public-transport-format/blob/master/modules.md) - modules that also use FPTF\n\n\n## Contributing\n\nIf you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit [the issues page](https://github.com/juliuste/sncf/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fsncf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliuste%2Fsncf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fsncf/lists"}