Giter Site home page Giter Site logo

derhuerst / generate-db-shop-urls Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 4.0 256 KB

Given a journey, generate a URL for a matching Deutsche Bahn ticket.

Home Page: https://github.com/derhuerst/generate-db-shop-urls

License: Other

JavaScript 8.19% HTML 91.73% Shell 0.07%
deutsche-bahn shop url transit public-transport

generate-db-shop-urls's Introduction

generate-db-shop-urls

Magically generate Deutsche Bahn ticket URLs. Given a journey queried with hafas-client@5, it tries to generate a matching ticket link in the Deutsche Bahn shop. 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.
  • Because of how (bad) the shop works, the generated links will only be valid with a browser session that hasn't recently been used to search for a connection, or one without any cookies/session.

npm version Prosperity/Apache license support me via GitHub Sponsors chat with me on Twitter

Installing

npm install generate-db-shop-urls

Usage

generate-db-shop-urls expects one (outbound) or two (outbound & returning) journeys queried with hafas-client@5 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')

const outbound = await hafas.journeys(berlin, hamburg, {
	departure: new Date('2017-05-18T05:00+0200'),
	results: 1,
})
const returning = await hafas.journeys(hamburg, berlin, {
	departure: new Date('2017-05-19T12:00+0200'),
	results: 1,
})

const link = await generateTicketLink(outbound.journeys[0], {
	returning:  returning.journeys[0],
})
console.log(link)

API

async (outbound, opt = {}) => {}

opt overrides the default options which look as follows:

{
	// type of BahnCard, '0' = no bahncard
	// see https://gist.github.com/juliuste/202bb04f450a79f8fa12a2ec3abcd72d
	bahncard: '0',
	class: '2', // '1' or '2'
	age: 40, // age of the traveller
	returning: null // returning journey to match (optional)
}

License

This project is dual-licensed: My contributions are licensed under the Prosperity Public License, contributions of other people are licensed as Apache 2.0.

This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.

Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn’t count as use for a commercial purpose.

Get in touch with me to buy a commercial license or read more about why I sell private licenses for my projects.

The DB Haltestellendaten dataset used by this project is licensed under CC-BY 4.0.

Contributing

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

By contributing, you agree to release your modifications under the Apache 2.0 license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.