var router = require('express').Router();
var request  = require('request');

var baiduKey = process.env.baiduKey;
var expressAPI = process.env.expressAPI;
var busAPIOne = process.env.busAPIOne;
var busAPITwo = process.env.busAPITwo;
var busAPIThree = process.env.busAPIThree;

router.get('/weather', function(req, res, next) {
  var option = {
    url: 'http://api.map.baidu.com/telematics/v3/weather',
    qs: {
      ak: baiduKey,
      location: 'shanghai',
      output: 'json'
    }
  }

  request(option, function(error, response, body){
    var resData = JSON.parse(body);
    var tipt = resData.results[0].index[0];
    var weather = resData.results[0].weather_data[0];
    weather.tipt = tipt;
    res.send(weather);
  });
});

router.get('/express/:type/:postId', function(req, res, next){
  var type = req.params.type;
  var postId = req.params.postId;
  var option = {
    url: expressAPI,
    qs: {
      type: type,
      postid: postId
    }
  }

  request(option, function(error, response, body){
    res.send(JSON.parse(body));
  });
});


router.get('/bus/:name', function(req, res, next){
  var name = req.params.name;
  var option = {
    url: busAPIOne,
    qs: { name: name }
  }

  request(option, function(error, response, body){
    var busLine = JSON.parse(body);
    var lineName = busLine.line_name.trim();
    var lineId = busLine.line_id.trim();
    console.error(lineName, lineId);
  });
});

module.exports = router;

@@ -1189,32 +1189,52 @@
 me: name %7D%0A  %7D%0A%0A
+  var busLine = %7B%7D;%0A
   request(option
@@ -1272,27 +1272,20 @@
 y)%7B%0A    
-var busLine
+body
  = JSON.
@@ -1305,130 +1305,130 @@
     
-var lineName = busLine.line_name.trim();%0A    var lineId = busLine.line_id.trim();%0A    console.error(lineName, lineId);%0A  %7D
+for(key in body) %7B%0A      busLine%5Bkey%5D = body%5Bkey%5D.trim();%0A    %7D%0A    console.error(busLine);%0A  %7D);%0A%0A  console.error(busLine
 );%0A%7D

add bus api one