<commit_before>var Weibo = require('nodeweibo');    // require('nodeweibo') also works if you have installed nodeweibo via npm
var setting = require('./setting.json');   // get setting (appKey, appSecret, etc.)
var utility = require('zh.asoiaf.utility');
var wikia = new utility.Wikia();
var request = require('request');
var globalVar = {
		"debug": true, 
		"MSG_NOFOUND":"没找到相关信息。", 
		"MSG_ERR":"没玉米了，服务器罢工了。",
		"character_days_in_power":1,
		"character":"琼恩·雪诺"
	};
module.exports = {
	comment: function(source, access_token, content, id, cid){
		wikia.search(content, function(err, items) {
			var msg = null;
			if (err) {
				msg = globalVar.MSG_NOFOUND;
			} else if (!items || items.length == 0) {
				msg = globalVar.MSG_ERR
			} else {
				//it is a successful search
			}
			if (cid == null){
				var para = {
				    "source": source,
				    "access_token": access_token,
				    "comment": msg == null ? items[0].abstract.substring(0,120)+"... http://zh.asoiaf.wikia.com/index.php?curid=" + items[0].id : msg,
				    "id" : id
				}
				if(msg != MSG_ERR && msg != MSG_NOFOUND){
					Weibo.Comments.create(para, function(data){
						if (globalVar.debug){
							console.log(data);
						}
					});
				}
			}else{
				var para = {
				    "source": source,
				    "access_token": access_token,
				    "comment": msg == null ? items[0].abstract.substring(0,110)+"... http://zh.asoiaf.wikia.com/index.php?curid=" + items[0].id : msg,
				    "id" : id,
				    "cid" : cid
				}
				if(msg != MSG_ERR && msg != MSG_NOFOUND){
					Weibo.Comments.reply(para, function(data){
						if (globalVar.debug){
							console.log(data);
						}
					});
				}
			}
		});
		return 

	},
	status: function(source, access_token, content, username){
		wikia.search(content, function(err, items) {
			var msg = null;
			if (err) {
				msg = globalVar.MSG_NOFOUND;
			} else if (!items || items.length == 0) {
				msg = globalVar.MSG_ERR
			} else {
				//it is a successful search
			}
			var para = {
			    "source": source,
			    "access_token": access_token,
			    "status": msg == null ? "@"+username+" "+items[0].abstract.substring(0,110)+"... http://zh.asoiaf.wikia.com/index.php?curid=" + items[0].id : msg,  
			}
			if(msg != MSG_ERR && msg != MSG_NOFOUND){

				Weibo.Statuses.update(para, function(data){
					if (globalVar.debug){
						console.log(data);
					}
				}); 

			}
			
		});
	},
	specialStatus: function(source, access_token, type){

		if(type == "most viewed"){
			url = "http://zh.asoiaf.wikia.com/api/v1/Articles/Top?namespaces=0&category=%E4%BA%BA%E7%89%A9&limit=1";
			request.get(url, function(err, res, body){
				if (!err && res.statusCode == 200) {
					var winner = res.items[0].title;
					var obj = {};
					var msg;
					var imageurl;
					obj.title = winner;
					obj.width = 600;
					obj.height = 800;
					obj['abstract'] = 120;
					wikia.info(obj, function(err, data){
						if(!err){
							for (var id in data.items){<commit_msg>fix vital bug<commit_after>var Weibo = require('nodeweibo');    // require('nodeweibo') also works if you have installed nodeweibo via npm
var setting = require('./setting.json');   // get setting (appKey, appSecret, etc.)
var utility = require('zh.asoiaf.utility');
var wikia = new utility.Wikia();
var request = require('request');
var globalVar = {
		"debug": true, 
		"MSG_NOFOUND":"没找到相关信息。", 
		"MSG_ERR":"没玉米了，服务器罢工了。",
		"character_days_in_power":1,
		"character":"琼恩·雪诺"
	};
module.exports = {
	comment: function(source, access_token, content, id, cid){
		wikia.search(content, function(err, items) {
			var msg = null;
			if (err) {
				msg = globalVar.MSG_NOFOUND;
			} else if (!items || items.length == 0) {
				msg = globalVar.MSG_ERR
			} else {
				//it is a successful search
			}
			if (cid == null){
				var para = {
				    "source": source,
				    "access_token": access_token,
				    "comment": msg == null ? items[0].abstract.substring(0,120)+"... http://zh.asoiaf.wikia.com/index.php?curid=" + items[0].id : msg,
				    "id" : id
				}
				if(msg != globalVar.MSG_ERR && msg != globalVar.MSG_NOFOUND){
					Weibo.Comments.create(para, function(data){
						if (globalVar.debug){
							console.log(data);
						}
					});
				}
			}else{
				var para = {
				    "source": source,
				    "access_token": access_token,
				    "comment": msg == null ? items[0].abstract.substring(0,110)+"... http://zh.asoiaf.wikia.com/index.php?curid=" + items[0].id : msg,
				    "id" : id,
				    "cid" : cid
				}
				if(msg != globalVar.MSG_ERR && msg != globalVar.MSG_NOFOUND){
					Weibo.Comments.reply(para, function(data){
						if (globalVar.debug){
							console.log(data);
						}
					});
				}
			}
		});
		return 

	},
	status: function(source, access_token, content, username){
		wikia.search(content, function(err, items) {
			var msg = null;
			if (err) {
				msg = globalVar.MSG_NOFOUND;
			} else if (!items || items.length == 0) {
				msg = globalVar.MSG_ERR
			} else {
				//it is a successful search
			}
			var para = {
			    "source": source,
			    "access_token": access_token,
			    "status": msg == null ? "@"+username+" "+items[0].abstract.substring(0,110)+"... http://zh.asoiaf.wikia.com/index.php?curid=" + items[0].id : msg,  
			}
			if(msg != globalVar.MSG_ERR && msg != globalVar.MSG_NOFOUND){

				Weibo.Statuses.update(para, function(data){
					if (globalVar.debug){
						console.log(data);
					}
				}); 

			}
			
		});
	},
	specialStatus: function(source, access_token, type){

		if(type == "most viewed"){
			url = "http://zh.asoiaf.wikia.com/api/v1/Articles/Top?namespaces=0&category=%E4%BA%BA%E7%89%A9&limit=1";
			request.get(url, function(err, res, body){
				if (!err && res.statusCode == 200) {
					var winner = res.items[0].title;
					var obj = {};
					var msg;
					var imageurl;
					obj.title = winner;
					obj.width = 600;
					obj.height = 800;
					obj['abstract'] = 120;
					wikia.info(obj, function(err, data){
						if(!err){
							for (var id in data.items){
{'fraction_non_alphanumeric': 0.1749667994687915, 'fraction_numerical': 0.013944223107569721, 'mean_word_length': 2.7306501547987616, 'pattern_counts': {'":': 28, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '162346', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2180, 'n_words': 437}