Skip to content

Python API wrapper for Munich's unoffical S-Bahn API.

License

Notifications You must be signed in to change notification settings

OrangeTux/Bavaria

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bavaria

Bavaria is a Python API for obtaining live data of the S-Bahn system in Munich. This projects is a wrapper for the undocumented websocket API that used by the Livemap beta feature in the Munich Navigator-App.

Note: Currently the code is highly unstable.

Quickstart

Install Bavaria using:

$ pip install bavaria

The following snippet demonstrates how to subscribe on the newsticker channel. This channel provides news messages.

import asyncio

from bavaria import create_feed
from bavaria.api.messages import NewsTicker

def print_news_item(item):
    """ Print news item to stdout. """
    time = item.updated.strftime('%Y.%m.%d %H:%M')

    print(f'\033[0;37;42m{time}\033[m \033[0;37;41m{item.title}\033[m')
    print(f'{item.content}')


async def main():
    feed = await create_feed()

    # Fetch latest news items from channel 'newsticker'.
    await feed.get('newsticker')

    # Subscribe for new items on items 'newsticker'.
    await feed.subscribe('newsticker')

    try:
        async for item in feed:
            if isinstance(item, NewsTicker):
                for msg in item.messages:
                    print_news_item(msg)

    except KeyboardInterrupt:
        await feed.disconnect()


if __name__ == '__main__':
    asyncio.run(main())

Features

  • Newsticker

License

Bavaria is licensed under MIT License.

About

Python API wrapper for Munich's unoffical S-Bahn API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages