Skip to content

Examples

Cameron edited this page Dec 5, 2024 · 11 revisions

Just installed realtime-trains-py and need some examples?

We've got you covered. This page provides you with examples of how to run and use the API Wrapper.

Let's get started!

Firstly, you need to make sure the package is installed on your machine. Make sure you're running the latest version for the most optimised experience. To install, simply run:

pip install --upgrade realtime-trains-py

You will need to install some external required packages for the package to work. These include:

  • tabulate (required)
  • requests (required)

To install these, run:

pip install --upgrade [package]

Make sure you change [package] to either tabulate or requests.

Initialising

Initialising the package is super easy. If you're running the package in a terminal, follow the example below. If you're using a file to do this, skip to the next section.

Using the terminal for setup

When you open your terminal, make sure you're running python, or you won't be able to do anything.

Start by typing the following line into your terminal. Make sure you click enter afterwards.

from realtime_trains_py import RealtimeTrainsPy

For the next part, you'll need a username and password. I don't have a username or password.

Run the command below - make sure you change the credentials to your ones or you'll get an error when you try running the code later.

rtt = RealtimeTrainsPy(username = "[your_username]", password = "[your_password]", complexity = "[select_type]")

And that's how to set up the realtime-trains-py package using the terminal. It's super easy.

Using a file for setup

When you open your file, make sure it's a .py file, or you won't be able to do anything.

Start by typing the following line into your file.

from realtime_trains_py import RealtimeTrainsPy

For the next part, you'll need a username and password. I don't have a username or password.

Below the line you just wrote, type the following - make sure you change the credentials to your ones or you'll get an error when you try running the code later.

rtt = RealtimeTrainsPy(username = "[your_username]", password = "[your_password]", complexity = "[select_type]")

The whole file should look like this:

from realtime_trains_py import RealtimeTrainsPy

rtt = RealtimeTrainsPy(username = "[your_username]", password = "[your_password]", complexity = "[select_type]")

And that's how to set up the realtime-trains-py package in a file. Now you're ready to start crunching the data!

Clone this wiki locally