def getTrain(self, TN): URL_Train = "https://erail.in/rail/getTrains.aspx?TrainNo=" + str( TN) + "&DataSource=0&Language=0&Cache=true" try: return Prettify().TrainsToJson(get(URL_Train).text)[0] except: return {'error': 'Unexpected Server Response'}
def getRoute(self, TN): ID = self.getTrain(TN) try: ID['error'] except KeyError: ID = ID['train_base']['train_id'] URL_Route = "https://erail.in/data.aspx?Action=TRAINROUTE&Password=2012&Data1=" + ID + "&Data2=0&Cache=true" return Prettify().StationToJson(get(URL_Route).text)
def getTrain(self, TN): URL_Train = "http://erail.in/rail/getTrains.aspx?TrainNo=" + str( TN) + "&DataSource=0&Language=0&Cache=true" fh = urllib.request.urlopen(URL_Train) data = fh.read() try: return Prettify().TrainsToJson(data.decode("utf-8")) except: return {'error': 'Unexpected Server Response'}
def getRoute(self,TN): ID = self.getTrain(TN) try: ID['error'] except KeyError: ID = ID['train_base']['train_id'] URL_Route = "https://erail.in/data.aspx?Action=TRAINROUTE&Password=2012&Data1="+ID+"&Data2=0&Cache=true" fh = urllib.request.urlopen(URL_Route) data = fh.read() return Prettify().StationToJson(data.decode("utf-8"))
def getFare(self, TN, F, T): URL_Fare = "https://erail.in/data.aspx?Action=GetTrainFare&train=" + str( TN) + "&from=" + F + "&to=" + T return Prettify().FareToJson(get(URL_Fare).text)
def getAvailability(self, TN, SSTN, DSTN, CLS, QT, DD, MM): URL_Avail = "https://d.erail.in/AVL_Request?Key=" val = '_'.join([str(TN), SSTN, DSTN, CLS, QT, str(DD) + '-' + str(MM)]) return Prettify().AvailToJson(get(URL_Avail + val).text)
def getAllTrains(self, F, T): URL_Trains = "https://erail.in/rail/getTrains.aspx?Station_From=" + F + "&Station_To=" + T + "&DataSource=0&Language=0&Cache=true" return Prettify().TrainsToJson( get(URL_Trains, headers={ 'User-Agent': gua() }).text)
def getFare(self, TN, F, T): URL_Fare = "https://erail.in/data.aspx?Action=GetTrainFare&train=" + str( TN) + "&from=" + F + "&to=" + T fh = urllib.request.urlopen(URL_Fare) data = fh.read() return Prettify().FareToJson(data.decode("utf-8"))
def getAllTrains(self, F, T): URL_Trains = "https://erail.in/rail/getTrains.aspx?Station_From=" + F + "&Station_To=" + T + "&DataSource=0&Language=0&Cache=true" fh = urllib.request.urlopen(URL_Trains) data = fh.read() return Prettify().TrainsToJson(data.decode("utf-8"))