Post Jobs

Railway API | india Railway api

INDIAN RAIL API provides information related to Indian Railways Trains

Railway API is the solution for your every question regarding Indian Railways. Here you can get ready APIs for:

  • Train Route
  • Seat Availability
  • Trains Between Stations
  • Train Name/Number
  • Train Arrivals at Station
  • Cancelled Trains
  • Rescheduled Trains
  • Station Name to Code
  • Station Code to Name
  • Station Autocomplete Suggest
  • Train Autocomplete Suggest

So now with this you can get every bit of information for any of your projects that may use a train status display board or a smart phone app. Now let’s see how to use this service.

Getting Started with Railway API

STEP 1: Creating Your Account

Before using this service, first you need to make an account on this website. You don’t need to fill much info, just provide your name and email ID. Click here to directly go to the sign up form. That’s it.After registration you will get your API key in your email. This key will also work as your login password.

STEP 2: Upgrade your Account (Optional)

Yes!, the limited version of this is free. For more, you need to pay for that. But it is worth paying if you are earning from this.

Railway API maintains a huge and updated collection of Trains and Stations data along with features like Train Live status, PNR status, Arrivals on Station, Trains Between Stations etc collected from various sources and then normalized.

This data is made available through a powerful REST ful API in a structured JSON format.

We simplify the process of acquiring and accessing Railways Data and help power your backend so you can focus on delivering value to your customers.

Python | Find Live running status and PNR of any train using Railway API

Railway API is organized around GET Requests. One can use this API to get information for Indian Railways regarding Live Train Status, PNR Status, Train Schedule, Station Details and other things.

To use this API, one must need the API key, which can be get form here

Note: User need to create an account on railwayapi.com then only can use the APIs.

# Python program to find live train
# status using RAILWAY API

# import required modules
import requests , json

# enter your api key here
api_key = “Your_API_Key”

# base_url variable to store url
base_url = “https://api.railwayapi.com/v2/live/train/”

# enter train_number here
train_number = “12056”

# enter current date in dd-mm-yyyy format
current_date = “20-06-2018”

# complete_url variable to
# store complete url address
complete_url = base_url + train_number + “/date/” + current_date + “/apikey/” + api_key + “/”

# get method of requests module
# return response object
response_ob = requests.get(complete_url)

# json method of response object convert
# json format data into python format data
result = response_ob.json()

# Now result contains list of nested dictionaries
# Check the value of “response_code” key is equal
# to “200” or not if equal that means record is
# found otherwise record is not found
if result[“response_code”] == 200 :

# train name is extracting from
# the result variable data
train_name = result[“train”][“name”]

# store the value or data of
# “route” key in variable y
y = result[“route”]

# source station name is extracting
# from the y variable data
source_station = y[0][“station”][“name”]

# destination station name is
# extracting from the y varibale data
destination_station = y[len(y)-1][“station”][“name”]

# store the value of “position”
# key in variable position
position = result[“position”]

# print following values
print(” train name : ” + str(train_name)
+ “\n source station : ” + str(source_station)
+ “\n destination station : “+ str(destination_station)
+ “\n current status : ” + str(position) )

else :
print(“record is not found for given request”)


# Python program to find PNR
# status using RAILWAY API

# import required modules
import requests, json

# Enter API key here
api_key = “Your_API_key”

# base_url variable to store url
base_url = “https://api.railwayapi.com/v2/pnr-status/pnr/”

# Enter valid pnr_number
pnr_number = “6515483790”

# Stores complete url address
complete_url = base_url + pnr_number + “/apikey/” + api_key + “/”

# get method of requests module
# return response object
response_ob = requests.get(complete_url)

# json method of response object convert
# json format data into python format data
result = response_ob.json()

# now result contains list
# of nested dictionaries
if result[“response_code”] == 200:

# train name is extracting
# from the result variable data
train_name = result[“train”][“name”]

# train number is extracting from
# the result variable data
train_number = result[“train”][“number”]

# from station name is extracting
# from the result variable data
from_station = result[“from_station”][“name”]

# to_station name is extracting from
# the result variable data
to_station = result[“to_station”][“name”]

# boarding point station name is
# extracting from the result variable data
boarding_point = result[“boarding_point”][“name”]

# reservation upto station name is
# extracting from the result variable data
reservation_upto = result[“reservation_upto”][“name”]

# store the value or data of “pnr”
# key in pnr_num variable
pnr_num = result[“pnr”]

# store the value or data of “doj” key
# in variable date_of_journey variable
date_of_journey = result[“doj”]

# store the value or data of
# “total_passengers” key in variable
total_passengers = result[“total_passengers”]

# store the value or data of “passengers”
# key in variable passengers_list
passengers_list = result[“passengers”]

# store the value or data of
# “chart_prepared” key in variable
chart_prepared = result[“chart_prepared”]

# print following values
print(” train name : ” + str(train_name)
+ “\n train number : ” + str(train_number)
+ “\n from station : ” + str(from_station)
+ “\n to station : ” + str(to_station)
+ “\n boarding point : ” + str(boarding_point)
+ “\n reservation upto : ” + str(reservation_upto)
+ “\n pnr number : ” + str(pnr_num)
+ “\n date of journey : ” + str(date_of_journey)
+ “\n total no. of passengers: ” + str(total_passengers)
+ “\n chart prepared : ” + str(chart_prepared))

# looping through passenger list
for passenger in passengers_list:

# store the value or data
# of “no” key in variable
passenger_num = passenger[“no”]

# store the value or data of
# “current_status” key in variable
current_status = passenger[“current_status”]

# store the value or data of
# “booking_status” key in variable
booking_status = passenger[“booking_status”]

# print following values
print(” passenger number : ” + str(passenger_num)
+ “\n current status : ” + str(current_status)
+ “\n booking_status : ” + str(booking_status))

else:
print(“record is not found for given request”)

Output :

train name : DOON EXPRESS
train number : 13009
from station : LUCKNOW
to station : DEHRADUN
boarding point : LUCKNOW
reservation upto : DEHRADUN
pnr number : 6515483790
date of journey : 01-07-2018
total no. of passengers: 1
chart prepared : False
passenger number : 1
current status : RLWL/-/16/GN
booking_status : RLWL/-/23/GN



0Shares

About

Note:- sarkariresultindia.org is now the No. 1 website for Government Jobs information. Our aim is to provide information in a simplified manner so that users can easily identify the jobs as per their choice

WhatsApp No.7005643721

0Shares