Skip to content
Magically generate Deutsche Bahn ticket URLs.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.editorconfig
.gitignore
.travis.yml
example.js
index.js
license.md
package.json
readme.md
todo

readme.md

generate-db-shop-urls

Magically generate Deutsche Bahn ticket URLs. Searches for a ticket link in the Deutsche Bahn shop that matches the journey you passed as a query. Caveats:

  • Uses a lot of scraping, as there is no (publicly accessible) machine-readable interface to the ticket system. This makes generate-db-shop-urls brittle.

npm version build status ISC-licensed chat on gitter support me on Patreon

Installing

npm install generate-db-shop-urls

Usage

generate-db-shop-urls accepts a form very similar to the Friendly Public Transport Format 1.1.1 as input.

const createHafas = require('db-hafas')
const generateTicketLink = require('generate-db-shop-urls')

const berlin = '8096003'
const hamburg = '8000157'
const hafas = createHafas('my-awesome-program')

// default options
const options = {
	bahncard: '0', // bahncard id (0 = no bahncard, see https://gist.github.com/juliuste/202bb04f450a79f8fa12a2ec3abcd72d)
	class: '2', // '1' or '2'
	age: 40, // age of the traveller
	returning: null // no returning journeys
}

Promise.all([
	hafas.journeys(berlin, hamburg, {
		departure: new Date('2017-05-18T05:00+0200'),
		results: 1
	}),
	hafas.journeys(hamburg, berlin, {
		departure: new Date('2017-05-19T12:00+0200'),
		results: 1
	})
])
.then(([outboundJourneys, returningJourneys]) => {
	options.returning = returningJourneys[0]
	return generateTicketLink(outboundJourneys[0], options)
})
.then(console.log, console.error)

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

You can’t perform that action at this time.