My Interface to Indian Railways(part 1)

Note: You can find the code backing this demo here and the part 2 here.

I hate the official website of Indian Railways and I thought it would be fun to know more about trains through an interface which is not an absolute trainwreck. Here is my humble attempt towards that lofty goal, all aboard the (not so) crazy train (of thought):

Find station by name

We know the name of the station and want to find its station code:

In [1]:
import train_of_thought as tot

tot.find_station_by_name("mumbai")
Out[1]:
code name
0 CSTM MUMBAI CST
1 BCT MUMBAI CENTRAL
2 DDR MUMBAI(DADAR)
3 BCL MUMBAI CENTRAL(L)

Partial names work too:

In [2]:
tot.find_station_by_name("mum")
Out[2]:
code name
0 CSTM MUMBAI CST
1 BCT MUMBAI CENTRAL
2 DDR MUMBAI(DADAR)
3 BCL MUMBAI CENTRAL(L)
4 MBQ MUMBRA

Find information about a particular station

Now that we know the station code, we can find more information about the corresponding station:

In [3]:
tot.code_info("CSTM")
Out[3]:
Station(code='CSTM', name='MUMBAI CST', lat=18.9398208, lng=72.835467600000001)

We can see the station on an interactive map(we can zoom in or out and click on the marker to know more about the location it represents):

In [4]:
tot.find_station_on_map("CSTM")
Out[4]:

We can zoom in and see the station and the railway tracks:

In [5]:
tot.find_station_on_map("CSTM", zoom_start_pioneer = 16)
Out[5]:

Find nearby stations

We can also find all the nearby stations:

In [6]:
tot.find_nearby_stations_on_map("CSTM")
Out[6]:

Find train by name

We know the (partial) name of the train and want to find its number:

In [7]:
tot.find_train_by_name("shan")
Out[7]:
name number
0 SHAN-E-BPL EXP 12155
1 SHAN-E- BHOPAL EXP 12156
2 SHANTINIKETAN EXP 12337
3 SHANTINIKETAN EXP. 12338
4 SHANE PUNJAB EXPRESS 12497
5 SHANE PUNJAB EXPRESS 12498
6 BBS-SBC PRASHANTI 18463

Find information about a particular train

Now that we know the train number, we can find more information about the corresponding train:

In [8]:
tot.get_train_info(12155)
Out[8]:
Train(number='12155', name='SHAN-E-BPL EXP', runs_on='MON,TUE,WED,THU,FRI,SAT,SUN')

We can also find its route:

In [9]:
tot.get_train_route(12155)
Out[9]:
code fullname distance day halt scharr schdep
0 HBJ HABIBGANJ 0 1 -1 SOURCE 21:05
1 BPL BHOPAL JN 6 1 5 21:15 21:20
2 BHS VIDISHA 59 1 2 22:08 22:10
3 BAQ GANJ BASODA 98 1 2 22:39 22:41
4 BINA BINA JN 144 1 5 23:30 23:35
5 JHS JHANSI JN 295 2 10 01:35 01:45
6 GWL GWALIOR JN. 392 2 5 02:55 03:00
7 MRA MORENA 431 2 2 03:25 03:27
8 AGC AGRA CANTT 511 2 3 04:47 04:50
9 NZM HAZRAT NIZAMUDDIN 698 2 -1 08:00 DEST

We can also see the train route on an interactive map:

In [10]:
tot.see_train_route(12155)
Out[10]:

We can also see its live running status:

In [11]:
tot.see_live_train_status(12155, "11-08-2017")
----- Live running status of: 12155 ( SHAN-E-BPL EXP ) -----
Train departed from SITHOULI(STLI) and late by 0 minutes.
Out[11]: