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 }
  }

  var busLine = {};
  request(option, function(error, response, body){
    body = JSON.parse(body);
    for(key in body) {
      busLine[key] = body[key].trim();
    }
    console.error(busLine);
  });

  console.error(busLine);
});

module.exports = router;

@@ -1364,16 +1364,285 @@
 );%0A    %7D
+%0A%0A    var op = %7B%0A      url: busAPITwo,%0A      qs: %7B%0A        name: busLine.line_name,%0A        lineid: busLine.line_id%0A      %7D%0A    %7D%0A    request(option, function(error, response, body)%7B%0A      body = JSON.parse(body);%0A      body.busLine = busLine;%0A    %7D%0A    res.send(body);
 %0A    con
@@ -1692,16 +1692,24 @@
 (busLine
+, '1111'
 );%0A%7D);%0A%0A

add bus api tow