<commit_before>/**
 * Module dependencies.
 */

var martaApi = require('./marta_api.js')
var martaApiInstance = new martaApi()

var appId = 'amzn1.echo-sdk-ams.app.655fae42-075f-4425-827b-8999daeb188a'

//NEW
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var AmazonEchoApp = require('node-alexa');
var redis = require('redis');
var url = require('url');
var util = require('util');
var redisURL = url.parse(process.env.REDISCLOUD_URL); //Heroku Redis
var client = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
client.auth(redisURL.auth.split(":")[1]);


app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));


var echoApp = new AmazonEchoApp(client, "marta-times", appId);
echoApp.decorateAppWithRoutes('/', app);

echoApp.on(echoApp.TYPE_LAUNCH_REQUEST, function(callback, userId, sessionInfo, userObject){
    var shouldEndSession = false;
    var speechText = "Welcome to the Marta App";
    var cardTitle = "Marta App Launched";
    var cardSubtitle = "userId " + userId;
    var cardContents = "Try a new command like 'Alexa, ask Marta when does the north bound train arrive at Midtown station'";
    var sessionObject = false;
    if(!userObject){
        //no long term persistance for this use
    }
    else{
        //this user has a long term storage session 
    }
    callback(shouldEndSession, speechText, cardTitle, cardSubtitle, cardContents, sessionObject);
});

function handleError(errorText, callback, sessionObject) {
  console.log("Error: " + errorText);
  callback(shouldEndSession, errorText, "Error", errorText, "", sessionObject);
}

echoApp.on(echoApp.TYPE_INTENT_REQUEST, function(callback, userId, sessionInfo, userObject, intent){
    if(intent.name === 'Marta'){
        if(intent.slots) {
          console.log("FULL INTENT: " + util.inspect(intent, false, null));
          console.log("SLOTS: " + util.inspect(intent.slots, false, null));
          console.log("STATION: " + util.inspect(intent.slots['Station'], false, null));
          var direction, station;
          
          station = intent.slots['Station'].value;
          if(station) {
            direction = intent.slots['Direction'].value;
            if(!direction) {
              handleError("Must specify which direction for " + station, callback, sessionObject);
            }
          } else {
            handleError("Must specify a Marta station", callback, sessionObject);
          }
          
          martaApiInstance.getPassage(station, direction, function logResult(err, result) {
           console.log(result)
           var shouldEndSession = true;
           var cardSubtitle = "userId " + userId;
            var cardContents = result;
            var sessionObject = false;

            var speechText = "The next" + direction "bound train will arrive at " + station + "station in " result;
            var cardTitle = direction "train at " + station + " in " + result;<commit_msg>fix syntax error in app code<commit_after>/**
 * Module dependencies.
 */

var martaApi = require('./marta_api.js')
var martaApiInstance = new martaApi()

var appId = 'amzn1.echo-sdk-ams.app.655fae42-075f-4425-827b-8999daeb188a'

//NEW
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var AmazonEchoApp = require('node-alexa');
var redis = require('redis');
var url = require('url');
var util = require('util');
var redisURL = url.parse(process.env.REDISCLOUD_URL); //Heroku Redis
var client = redis.createClient(redisURL.port, redisURL.hostname, {no_ready_check: true});
client.auth(redisURL.auth.split(":")[1]);


app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));


var echoApp = new AmazonEchoApp(client, "marta-times", appId);
echoApp.decorateAppWithRoutes('/', app);

echoApp.on(echoApp.TYPE_LAUNCH_REQUEST, function(callback, userId, sessionInfo, userObject){
    var shouldEndSession = false;
    var speechText = "Welcome to the Marta App";
    var cardTitle = "Marta App Launched";
    var cardSubtitle = "userId " + userId;
    var cardContents = "Try a new command like 'Alexa, ask Marta when does the north bound train arrive at Midtown station'";
    var sessionObject = false;
    if(!userObject){
        //no long term persistance for this use
    }
    else{
        //this user has a long term storage session 
    }
    callback(shouldEndSession, speechText, cardTitle, cardSubtitle, cardContents, sessionObject);
});

function handleError(errorText, callback, sessionObject) {
  console.log("Error: " + errorText);
  callback(shouldEndSession, errorText, "Error", errorText, "", sessionObject);
}

echoApp.on(echoApp.TYPE_INTENT_REQUEST, function(callback, userId, sessionInfo, userObject, intent){
    if(intent.name === 'Marta'){
        if(intent.slots) {
          console.log("FULL INTENT: " + util.inspect(intent, false, null));
          console.log("SLOTS: " + util.inspect(intent.slots, false, null));
          console.log("STATION: " + util.inspect(intent.slots['Station'], false, null));
          var direction, station;
          
          station = intent.slots['Station'].value;
          if(station) {
            direction = intent.slots['Direction'].value;
            if(!direction) {
              handleError("Must specify which direction for " + station, callback, sessionObject);
            }
          } else {
            handleError("Must specify a Marta station", callback, sessionObject);
          }
          
          martaApiInstance.getPassage(station, direction, function logResult(err, result) {
           console.log(result)
           var shouldEndSession = true;
           var cardSubtitle = "userId " + userId;
            var cardContents = result;
            var sessionObject = false;

            var speechText = "The next" + direction + "bound train will arrive at " + station + "station in " + result;
            var cardTitle = direction + "train at " + station + " in " + result;
{'fraction_non_alphanumeric': 0.1303395399780942, 'fraction_numerical': 0.008762322015334063, 'mean_word_length': 3.3276912660798916, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '686896', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1869, 'n_words': 482}