Exemple #1
0
router.get('/', function (req, res) {
    // res.render('index', { title: 'Express' });

    factual.get('/t/places?q=starbucks&include_count=true', function (error, result) {
        console.log("show " + result.included_rows + "/" + result.total_row_count + " rows:", result.data);
        res.send(result.data);
    });



});
Exemple #2
0
app.post('/restaurantFinder', function(req, res){
    res.contentType('application/json');
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    var resJSON;
   var factual = new Factual('uQS3leKgmggjsYBVQeiTGaOp8VcIcZzRjnAzi2rZ', 'P3kbXUe19xcMwYtpNmomGzjb851HfceurUrZbYdc');
   search_form = req.body;  
   console.log(search_form.cuisine);
   cuisineList = (search_form.cuisine).split(" ");
    console.log(cuisineList.length);
    // <-- search items
    if(cuisineList.length==1)
        var url='/t/restaurants-us?filters={"$and":[{"cuisine":{"$eq":"'+cuisineList[0]+'"}},{"locality":"'+search_form.locality+'"}]}';
    if(cuisineList.length==2)
        var url='/t/restaurants-us?filters={"$and":[{"cuisine":{"$eq":"'+cuisineList[0]+'"}},{"cuisine":{"$eq":"'+cuisineList[1]+'"}},{"locality":"'+search_form.locality+'"}]}';
    if(cuisineList.length==3)
        var url='/t/restaurants-us?filters={"$and":[{"cuisine":{"$eq":"'+cuisineList[0]+'"}},{"cuisine":{"$eq":"'+cuisineList[1]+'"}},{"cuisine":{"$eq":"'+cuisineList[2]+'"}},{"locality":"'+search_form.locality+'"}]}';
    if(cuisineList.length==4)
        var url='/t/restaurants-us?filters={"$and":[{"cuisine":{"$eq":"'+cuisineList[0]+'"}},{"cuisine":{"$eq":"'+cuisineList[1]+'"}},{"cuisine":{"$eq":"'+cuisineList[2]+'"}},{"cuisine":{"$eq":"'+cuisineList[3]+'"}},{"locality":"'+search_form.locality+'"}]}';
    if(cuisineList.length==5)
       var url='/t/restaurants-us?filters={"$and":[{"cuisine":{"$eq":"'+cuisineList[0]+'"}},{"cuisine":{"$eq":"'+cuisineList[1]+'"}},{"cuisine":{"$eq":"'+cuisineList[2]+'"}},{"cuisine":{"$eq":"'+cuisineList[3]+'"}},{"cuisine":{"$eq":"'+cuisineList[4]+'"}},{"locality":"'+search_form.locality+'"}]}';
      console.log(url);
       factual.get(url, function (error, items) {
  console.log(items.data);
  console.log(items.included_rows);
  console.log("\n");
  console.log("Recommended Restaurants");
  console.log("-----------------------\n")
  restaurantJSON= {"details":[]};
  for(i=0; i<items.included_rows;i++)
  { 
    console.log((i+1)+") "+items.data[i].name+"\nAddress: "+items.data[i].address+"\nCuisines served: "+ items.data[i].cuisine+"\nPrice range: "+items.data[i].price+"\nRating: "+items.data[i].rating+"\nTelephone Number: "+items.data[i].tel+"\nWebsite: "+ items.data[i].website);
    restaurantJSON.details[i]={"name":items.data[i].name,"address":items.data[i].address,"cuisine":items.data[i].cuisine,"price":items.data[i].price,"rating":items.data[i].rating,"telephone": items.data[i].tel,"website":items.data[i].website};
    console.log(restaurantJSON.details[i].cuisine);
    console.log("\n");     

  }
  console.log(restaurantJSON);
  //var restaurantJSON= JSON.stringify(restaurant);
  //console.log(restaurantJSON);
  //res.send(restaurant);
 res.send(restaurantJSON);
});
  
});
Exemple #3
0
    return new Promise (function(resolve, reject){
        factual.get('/t/products-cpg-nutrition?q=' + id, function (error, res) {
            var ingredients = res.data[0].ingredients;
            var brand = res.data[0].brand;
            var category = res.data[0].category;
            var image_urls = res.data[0].image_urls[0];
            var product_name = res.data[0].product_name;

            //console.log(product_name);
            //console.log(definitions(ingredients));

            resolve({
                ingredients: ingredients,
                brand: brand,
                category: category,
                image_urls: image_urls,
                product_name: product_name,
                ingredientToInfoMapping: foodData
            });

        });
    });
Exemple #4
0
//Not used; calls factual based on yelp id to fill in information
function getFactual(id, country) {
    var Factual = require('factual-api');
    var factual = new Factual('LSCM3IwVY4QaENnrM4tIsHXQodwp3ROQaJ0zADjX', 'Rcw2Z89qHfZBmKYQjEuBoyvHsAUKtk0ZvvayjDqT');
    if (country === "us" || country === "fr" || country === "gb" || country === "de" || country === "au") {
        var database = '/t/restaurants-' + country;
        var cross = '/t/crosswalk?filters={"url": "http://www.yelp.com/biz/' + id + '"}';
        factual.get(cross)
            .then(function (result) {
                //console.log(res.data[0]);
                factual.get(database, {filters: {"factual_id": result.data[0].factual_id}})
                    .then(function (res) {
                        //console.log("result: ", res.data[0]);
                        $(id).append(res.data[0]);
                    })
                    .catch(function (err) {
                        console.log('error_factual_restaurants');
                    });
            })
            .catch(function (error) {
                console.log('error_factual_id');
            });
    }
}
Exemple #5
0
exports.go = function() {
    // build your api calls here

    // var key = "ucdlw2DnmCkN0BkFUNWu8tnwGYG2xsm6ySqIqAp1"
    //var url = "http://toxgate.nlm.nih.gov/cgi-bin/sis/search2/x?dbs+<db>:<keyword>?key=" + key;
    //
    // var url = "http://api.v3.factual.com/t/products-cpg?q=shampoo?key=";
    // console.log("testing api calls");

    // return new Promise(function (resolve, reject) {
    //     request(url, function (error, response, body){
    //         if (error) {
    //             reject(error);
    //         }
    //         console.log(response);
    //         return JSON.parse(body);
    //     })
    // })
    var upc = 611269357011;


    factual.get('/t/products-cpg-nutrition?q=' + upc, function (error, res) {
        var ingredients = res.data[0].ingredients;
        var brand = res.data[0].brand;
        var category = res.data[0].category;
        var image_urls = res.data[0].image_urls[0];
        var product_name = res.data[0].product_name;

        console.log(product_name);

        // res.render('product', {Products: brand});

        console.log(definitions(ingredients));

    });
}
// World Geographies doc:
// http://developer.factual.com/display/docs/World+Geographies
var auth = require('./auth');
var Factual = require('factual-api');
var factual = new Factual(auth.key, auth.secret);
factual.startDebug();

factual.get('/t/world-geographies?select=neighbors&filters={"factual_id":{"$eq":"08ca0f62-8f76-11e1-848f-cfd5bf3ef515"}}', function (error, res) {
  console.log(res.data);
});
// match api doc:
// http://developer.factual.com/api-docs/#Match 

var auth = require('./auth');
var Factual = require('factual-api');
var factual = new Factual(auth.key, auth.secret);
factual.startDebug();

factual.get('/t/places-us/match?values={"name":"McDonalds","address":"10451 Santa Monica Blvd","region":"CA","postcode":"90025"}', function (error, res) {
  console.log(res.data);
});

Exemple #8
0
app.get('/restaurants-api', function(req, res){

    var q = req.query["q"];
    var ll = req.query["ll"];
    var tokens = ll.split(",");
    var lat = 0, lon = 0;

    if (tokens.length == 2) {

        //todo, check if valid numbers & within appropriate bounds

        lat = parseFloat(tokens[0]);
        lon = parseFloat(tokens[1]);
    }
    else {
        //would be better to throw an error, but sending empty response for now
        writeEmptyResponse( res );
        return;
    }

    //http://api.v3.factual.com/t/restaurants-us
    //get source data points from factual
    factual.get('/t/restaurants-us',{q:q, sort:"$distance:asc", limit:50, geo:{"$circle":{"$center":[lat,lon],"$meters":FACTUAL_RADIUS_METERS}}, "include_count":"true"}, function (factual_error, factual_res) {
    
        if (!factual_res.data) {
            writeEmptyResponse( res );
            return;
        }

        var data = factual_res.data;
        var points = [];
        var map = {};

        for (var x=0; x<data.length; x++) {
            var item = data[x];
            points.push({
                id:  item.factual_id,
                lat: item.latitude,
                lng: item.longitude
            });
            map[item.factual_id] = item;
        }
        //console.log( points );


        if ( factual_res.data.length > 0 ) {

            var params = {
                "format": "json",
                "origin": {"lat": lat, "lng": lon},
                "travel_time": MAX_WALK_TIME_SECONDS,
                "mode": "walking_train",
                "points": points
            }

            var headers = {
                "X-app-id": TT_APP_ID,
                "X-app-key": TT_APP_KEY
            }


            //rank by walking distance (time in seconds)
            request({url:TT_DATA_URL, method:"POST", json:params, headers:headers}, function (tt_error, tt_res, tt_body) {

                var output = [];

                if (!tt_error && tt_res.statusCode == 200) {

                    var result = eval(tt_body);
                    //console.log( result.length )

                    if ( result.length > 0 ){
                        for (var x=0; x<result.length; x++) {
                            var item = result[x];
                            for ( var key in item ){
                                //console.log( key, item )
                                var target = map[key];
                                if ( target ){
                                    target[ "travel_time_seconds"] = item[key];
                                    target[ "travel_time_formatted"] = formatTime( item[key] );
                                    target[ "distance"] = formatDistance( target["$distance"] );
                                    output.push(target);
                                }
                            }
                        }

                        output = output.sort(function(a,b){return a.travel_time_seconds - b.travel_time_seconds});

                        delete params.points;
                        request({url:TT_MAPS_URL, method:"POST", json:params, headers:headers}, function (ttt_error, ttt_res, ttt_body) {
                            //console.log(ttt_body);

                            if (!tt_error && tt_res.statusCode == 200) {

                                var polygons = eval(ttt_body);
                                var result = {
                                    points: output,
                                    polygons: polygons
                                }

                                res.send(JSON.stringify(result));
                            }
                            else  {
                                writeEmptyResponse( res );
                            }
                        });
                    }
                    else {
                        writeNonWalkingResponse( data, map, res );
                    }


                }
                else  {

                    writeNonWalkingResponse( data, map, res );
                }

            });

        } else {
            writeEmptyResponse( res );
        }

    });

});
// resolve api doc:
// http://developer.factual.com/api-docs/#Resolve

var auth = require('./auth');
var Factual = require('factual-api');
var factual = new Factual(auth.key, auth.secret);
factual.startDebug();

// resovle from name and address info
var data = JSON.stringify({
        name: "AT&T Center",
        address: "1150 S Olive St",
        locality: "Los Angeles",
        region: "CA",
        postcode: "90015",
        country: "us"
});

factual.get('/t/places-us/resolve',
            {values:data},
            function (error, res) {
                if (error) { console.log(error); }
                else if (res) { console.log(res); }
});
// resolve api doc:
// http://developer.factual.com/api-docs/#Resolve

var auth = require('./auth');
var Factual = require('factual-api');
var factual = new Factual(auth.key, auth.secret);
factual.startDebug();

// resovle from name and address info
factual.get('/t/places-us/resolve?values={"name":"McDonalds","address":"10451 Santa Monica Blvd","region":"CA","postcode":"90025"}', function (error, res) {
  console.log(res.data);
});


// resolve from name and geo location
factual.get('/t/places-us/resolve?values={"name":"McDonalds","latitude":34.05671,"longitude":-118.42586}', function (error, res) {
  console.log(res.data);
});