npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generate-db-shop-urls

v4.0.0

Published

Magically generate Deutsche Bahn ticket URLs.

Downloads

28

Readme

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.

Buy a commercial license or read more about why I sell private licenses for my projects.

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.