var mongoose = require('mongoose');
var Post = require('../models/Post').Post;
var config = require('../config');
var http = require('http');

var site = "";
var token = "";

var options = {
  host: 'data.zz.baidu.com',
  path: '/urls?site=' + site + '&token=' + token,
  method: 'POST',
  headers: {
    'Accept': '*/*',
var callback = function (res) {
	var buffers = [];
	var nread = 0;
  res.on('data', function (chunk) {
    buffers.push(chunk);
    nread += chunk.length;
  });
  res.on('end', function () {
		console.log(buffers);
  });
}

var req = http.request(options, callback);

mongoose.connect(config.db.production);

var db = mongoose.connection;
db.once('open', function (callback) {
	Post.find({}, {pid: 1})
	.exec(function (err, posts) {
		var urls = posts.map(function (post) {
			return 'http://' + config.site.url + '/post/' + post.pid;
		});
		var data = urls.join('\n');
		console.log(data,urls.length);
		req.write(data);
		req.end();
	});
});
    'Connection': 'Keep-Alive',
    'User-Agent': 'curl/7.12.1 '
  }
};
