Ejemplo n.º 1
0
 def ETA_Delayed_Response(self, webhook_req):
     response = ''
     station_data = ''
     train_number = ''
     station_name = ''
     date = webhook_req.get('date')
     outputContexts = webhook_req.get('outputContexts')
     for context in outputContexts:
         if ('eta_station_inputeta_auto_station_train_input-followup'
                 in context.get('name')):
             train_number = int(
                 context.get('parameters').get('train_number'))
             station_name = context.get('parameters').get('station_name')
             break
         if ('eta_train_station_autocorrect-followup'
                 in context.get('name')):
             train_number = int(
                 context.get('parameters').get('train_number'))
             station_name = context.get('parameters').get('station_name')
             break
         if ('eta_train_inputeta_station_train_autocorrect-followup'
                 in context.get('name')):
             train_number = int(
                 context.get('parameters').get('train_number'))
             station_name = context.get('parameters').get('station_name')
             break
     data = RailwayDB().getLiveTrainStatus(train_number, date)
     print(data)
     if data['response_code'] == 200:
         for route in data.get('route'):
             if (route.get('station').get('name') == station_name):
                 station_data = route
                 break
         position = data['position']
         if (station_data):
             if station_data["scharr"] == "Source":
                 responseText = "It reaches " + station_name + " station" + " on " + station_data[
                     'actarr_date'] + " ," + station_data['schdep']
             else:
                 responseText = "It reaches " + station_name + " station" + " on " + station_data[
                     'actarr_date'] + " ," + station_data['actarr']
             response = position + responseText
         else:
             response = station_name + " station is not in the route of the requested Train"
     if data['response_code'] == 210:
         response = "Looks like your train does not run on the date you mentioned"
     if data['response_code'] == 230:
         response = "Try again with a valid date"
     if data['response_code'] == 404:
         response = "I could not find any details for the requested Train and Station entries"
     if data['response_code'] == 405:
         response = "Oops! I could not communicate with the Indian Railways. There seems to be an issue with them."
     return jsonify({
         "queryResult": {
             "action": "ETA_Delayed_Final_Response",
             "fulfillmentText": response
         }
     })
Ejemplo n.º 2
0
 def EtaTrainActivity(self, webhook_req):
     station_name = ''
     parameters = webhook_req.get('queryResult').get('parameters')
     outputContexts = webhook_req.get('queryResult').get('outputContexts')
     for context in outputContexts:
         if ('eta-followup' in context.get('name')):
             station_name = context.get('parameters').get('station_name')
             break
     if (webhook_req.get('queryResult').get('parameters').get(
             'train_number')):
         trains = []
         train_number = webhook_req.get('queryResult').get(
             'parameters').get('train_number')
         train_detail = RailwayDB().getTrainNameNumber(
             parameters.get('train_number'))
         stations = RailwayDB().getStationAutoSuggest(
             parameters.get('station_name'))
         print(train_detail)
         print(stations)
         trains.append(train_detail)
         print(trains)
         if (type(train_detail) is dict and type(stations) is list):
             return jsonify({
                 "fulfillmentText": "Do you mean?",
                 "outputContexts": outputContexts,
                 "payload": {
                     "actual_data": True,
                     "trains": trains,
                     "stations": stations
                 }
             })
         if (type(train_detail) is not dict and type(stations) is list):
             return jsonify({
                 "fulfillmentText": trains,
             })
         if (type(train_detail) is dict and type(stations) is not list):
             return jsonify({
                 "fulfillmentText": stations,
             })
         if (type(train_detail) is not dict and type(stations) is not list):
             return jsonify({
                 "fulfillmentText":
                 "Oops! Looks like there are no trains and stations like you mentioned",
             })
     else:
         train_name = webhook_req.get('queryResult').get('parameters').get(
             'train_name')
         return jsonify({
             "fulfillmentText": "Wait for a moment!",
             "outputContexts": outputContexts,
             "payload": {
                 "actual_data": False,
                 "train_name": train_name,
                 "station_name": station_name,
                 "activity": "ETA_Delayed_Picker_Response"
             }
         })
Ejemplo n.º 3
0
 def trainStatusDelayedResponse(self,webhook_req):
     train_number = ''
     response = ''
     print("Herr")
     date = webhook_req.get('date')
     outputContexts = webhook_req.get('outputContexts')
     print(date)
     for context in outputContexts :
         if ( 'train_number_input-followup' in context.get('name') ):
             train_number = int(context.get('parameters').get('train_number'))
             break
     data = RailwayDB().getLiveTrainStatus(train_number, date)
     print(data)
     if data['response_code'] == 200 :
         position = data['position']
         print(position)
         if 'Source' in data['position'] :
             station_data = data.get('route')[0]
             station_name = station_data.get('station').get('name')
             words = position.split(" ")
             for word in words:
                 response = response + word + " "
                 if word == 'Source':
                     response = response + "i.e.., " + station_name + " "
             # response = position.replace( 'Source',station_name )
             print (response)
         elif 'Destination' in data['position'] :
             station_data = data.get('route')[ len(data.get('route')) - 1 ]
             station_name = station_data.get('station').get('name')
             words = position.split(" ")
             for word in words:
                 response = response + word + " "
                 if word == 'Destination':
                     response = response + "i.e.., " + station_name + " "
             # response = position.replace( 'Destination',station_name )
             print (response)
         else :
             response = position
     if data['response_code'] == 210 :
         response = "Looks like your train does not run on the date queried"
     if data['response_code'] == 230 :
         response = "Try again with a valid date."
     if data['response_code'] == 404 :
         response = "I could not find any live status for the requested Train"
     if data['response_code'] == 405 :
         response = "Oops! I could not communicate with the Indian Railways. There seems to be an issue with them."
     return jsonify({
         "queryResult" : {
             "action" : "train_status.TrainStatus_Delayed_Final_Response",
             "fulfillmentText": response
         }
     })
Ejemplo n.º 4
0
    def trainStatusMainActivity(self,webhook_req):
        trains = []
        parameters = webhook_req.get('queryResult').get('parameters')
        outputContexts = webhook_req.get('queryResult').get('outputContexts')
        if ( parameters.get('train_number') ):
            train_detail = RailwayDB().getTrainNameNumber(parameters.get('train_number'))
            trains.append(train_detail)
            if ( type(train_detail) is dict ):
                return jsonify({
                    "fulfillmentText" : "Do you mean?",
                    "outputContexts" : outputContexts,
                    "payload" : {
                        "actual_data" : True,
                        "trains" : trains
                    }
                })
            else :
                return jsonify({
                    "fulfillmentText" : trains,
                })
        if ( parameters.get('train_name') ):
            train_name = parameters.get('train_name')
            return jsonify({
                "fulfillmentText": "Wait for a moment!",
                "outputContexts" : outputContexts,
                "payload" : {
                    "actual_data" : False,
                    "train_name" : train_name,
                    "activity" : "TrainStatus_Delayed_Picker_Response"
                }
            })

        return jsonify({
            "fulfillmentText" : "Testing"
        })
Ejemplo n.º 5
0
 def etaDelayedPickerResoponse(self, data):
     print(data)
     trains = RailwayDB().getTrainAutoSuggest(data.get('train_name'))
     stations = RailwayDB().getStationAutoSuggest(data.get('station_name'))
     print(trains)
     print(stations)
     if (type(trains) is list and type(stations) is list):
         return jsonify({
             "queryResult": {
                 "action": "ETA_delayed_response",
                 "fulfillmentText": "Do you mean?",
                 "webhookPayload": {
                     "actual_data": True,
                     "trains": trains,
                     "stations": stations
                 }
             }
         })
     if (type(trains) is list and type(stations) is not list):
         return jsonify({
             "queryResult": {
                 "action": "ETA_delayed_response",
                 "fulfillmentText": stations
             }
         })
     if (type(trains) is not list and type(stations) is list):
         return jsonify({
             "queryResult": {
                 "action": "ETA_delayed_response",
                 "fulfillmentText": trains
             }
         })
     if (type(trains) is not list and type(stations) is not list):
         return jsonify({
             "queryResult": {
                 "action":
                 "ETA_delayed_response",
                 "fulfillmentText":
                 "Oops! Looks like there are no trains and stations like you mentioned",
             }
         })
Ejemplo n.º 6
0
 def PNRMainActivity(self, webhook_req):
     pnr_number = webhook_req.get('queryResult').get('parameters').get(
         'pnr_number')
     print(pnr_number)
     if (pnr_number):
         pnr_number = int(pnr_number)
         if (len(str(pnr_number)) == 10):
             return RailwayDB().getPnrStatus(pnr_number)
     outputContexts = webhook_req.get('queryResult').get('outputContexts')
     return jsonify({
         "fulfillmentText": "Enter valid 10 digit PNR number",
         "outputContexts": outputContexts,
         "followupEventInput": {
             "name": "pnr_status_fallback",
             "languageCode": "en-US",
         }
     })
Ejemplo n.º 7
0
 def trainStatusPickerDelayedResponse(self,data):
     trains = RailwayDB().getTrainAutoSuggest(data.get('train_name'))
     print(trains)
     if ( type(trains) is list ):
         return jsonify({
             "queryResult" : {
                 "action" : "train_status_delayed_response",
                 "fulfillmentText": "Do you mean?",
                 "webhookPayload" : {
                     "actual_data" : True,
                     "trains" : trains,
                 }
             }
         })
     else :
         return jsonify({
             "queryResult" : {
                 "action" : "train_status_delayed_response",
                 "fulfillmentText": trains
             }
         })
Ejemplo n.º 8
0
    def EtaMainActivity(self, webhook_req):
        trains = []
        parameters = webhook_req.get('queryResult').get('parameters')
        outputContexts = webhook_req.get('queryResult').get('outputContexts')
        if (parameters.get('train_number')):
            if (parameters.get('station_name')):
                #auto complete station name
                print(parameters.get('train_number'))
                print(parameters.get('station_name'))
                train_detail = RailwayDB().getTrainNameNumber(
                    parameters.get('train_number'))
                stations = RailwayDB().getStationAutoSuggest(
                    parameters.get('station_name'))
                print(train_detail)
                print(stations)
                trains.append(train_detail)
                print(trains)
                if (type(train_detail) is dict and type(stations) is list):
                    return jsonify({
                        "fulfillmentText": "Do you mean?",
                        "outputContexts": outputContexts,
                        "payload": {
                            "actual_data": True,
                            "trains": trains,
                            "stations": stations
                        }
                    })
                if (type(train_detail) is not dict and type(stations) is list):
                    return jsonify({
                        "fulfillmentText": trains,
                    })
                if (type(train_detail) is dict and type(stations) is not list):
                    return jsonify({
                        "fulfillmentText": stations,
                    })
                if (type(train_detail) is not dict
                        and type(stations) is not list):
                    return jsonify({
                        "fulfillmentText":
                        "Oops! Looks like there are no trains and stations like you mentioned",
                    })

            else:
                return jsonify({
                    "fulfillmentText":
                    "May I know the station name at which you are expecting the arrival?",
                    "outputContexts": outputContexts,
                    "followupEventInput": {
                        "name": "ETA_fallback_error_station",
                        "languageCode": "en-US",
                    }
                })

        elif (parameters.get('train_name')):
            if (parameters.get('station_name')):
                #auto complete station name
                #auto train name
                train_name = webhook_req.get('queryResult').get(
                    'parameters').get('train_name')
                station_name = webhook_req.get('queryResult').get(
                    'parameters').get('station_name')
                return jsonify({
                    "fulfillmentText": "Wait for a moment!",
                    "outputContexts": outputContexts,
                    "payload": {
                        "actual_data": False,
                        "train_name": train_name,
                        "station_name": station_name,
                        "activity": "ETA_Delayed_Picker_Response"
                    }
                })
                print(parameters.get('station_name'))
            else:
                return jsonify({
                    "fulfillmentText":
                    "May I know the station name at which you are expecting the arrival?",
                    "outputContexts": outputContexts,
                    "followupEventInput": {
                        "name": "ETA_fallback_error_station",
                        "languageCode": "en-US",
                    }
                })
                # call station name input intent
        elif (parameters.get('station_name')):
            return jsonify({
                "fulfillmentText":
                "May I know the train name or number which you are expecting the arrival?",
                "outputContexts": outputContexts,
                "followupEventInput": {
                    "name": "ETA_fallback_error_train",
                    "languageCode": "en-US",
                }
            })
            # auto complete station name
            # call train name input intent
            pass
        else:
            # call train name and station name input
            pass

        return jsonify({"fulfillmentText": "Checking Parameters"})