Ejemplo n.º 1
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.º 2
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
         }
     })