Beispiel #1
0
 .map(function(el) {
   if (el.retweeted_status) {
     return ent.decode(el.retweeted_status.text);
   }
   else {
     return ent.decode(el.text);
   }
 })
Beispiel #2
0
 Object.keys(obj).forEach(function(k) {
     var v = obj[k];
     if (typeof v == "string") {
         obj[k] = ent.decode(v);
     } else if (v instanceof Array) {
         for (var i=0; i < v.length; i++) {
             v[i] = ent.decode(v[i]);
         }
     }
 });
Beispiel #3
0
 .map(function(el) {
   var obj = {};
   if (el.retweeted_status) {
     obj.text = ent.decode(el.retweeted_status.text);
   }
   else {
     obj.text = ent.decode(el.text);
   }
   obj.id_str = el.id_str;
   obj.screen_name = el.user.screen_name;
   return obj;
 })
Beispiel #4
0
const titleFromAttr = function (article) {
	let match = article.description.match(/title="([\0-!#-\uffff]+)"/);
	if (match) {
		article.headTitle = decode(match[1]);
		return;
	}
	match = article.description.match(/" aria-label="([\0-!#-\uffff]+)"/);
	if (match) {
		article.headTitle = decode(match[1]);
		return;
	}
	logArticleToMail("Could not parse title", article.description);
};
Beispiel #5
0
						data.data.children.forEach(function(value) {
							var post = value.data;
							if (post.created_utc <= lastUpdate[channel]) return;

							if (post.created_utc > newLastUpdate) {
								newLastUpdate = post.created_utc;
							}

							console.log('annoucing new link: ' + post.title);

							var srData = reddits[channel][post.subreddit.toLowerCase()];
							var sub_color = srData.color ? srData.color : default_subreddit_color;
							
							if (post.distinguished === 'moderator') {
								post.author += ' [' + IRC_COLOR_CHAR + colors.green + 'M' + IRC_COLOR_CHAR + ']';
								post.title = IRC_COLOR_CHAR + colors.green + ZERO_WIDTH_SPACE + post.title + IRC_COLOR_CHAR;
							} else if (post.distinguished === 'admin') {
								post.author += ' [' + IRC_COLOR_CHAR + colors.red + 'A' + IRC_COLOR_CHAR + ']';
								post.title = IRC_COLOR_CHAR + colors.red + ZERO_WIDTH_SPACE + post.title + IRC_COLOR_CHAR;
							}

							var msg = (post.over_18 || srData.nsfl ? '[' + IRC_COLOR_CHAR + colors.red + 'NSFW' + IRC_COLOR_CHAR + '] ' : '')
							+ '[' + IRC_COLOR_CHAR + sub_color + post.subreddit + IRC_COLOR_CHAR + ']'
							+ ' [' + post.author + '] '
							// TODO: strip any irc formatting characters from the title since reddit doesn't
							+ ent.decode(post.title)
							+ (post.link_flair_text ? (' [' + ent.decode(post.link_flair_text) + ']') : '')
							+ ' [ https://reddit.com/' + post.id + ' ]'
							+ (!post.is_self ? ' [ ' + ent.decode(post.url) + ' ]' : '');

							if (!post.is_self) {
								sauce(ent.decode(post.url), function (err, results) {
									var best;

									if (!err && (best = results[0])) {
										shortenURL(best.link, function(err, url) {
											if (url) {
												msg += ' [S: ' + url + ' ]';
											} // else msg stays as is

											client.say(channel, msg);
										});
									} else {
										client.say(channel, msg);
									}
								});
							} else {
								client.say(channel, msg);
							}
						});
Beispiel #6
0
						data.data.children.forEach(function(value) {
							var post = value.data;
							if (post.created_utc <= lastUpdate[channel]) return;

							if (post.created_utc > newLastUpdate) {
								newLastUpdate = post.created_utc;
							}

							console.log('annoucing new link: ' + post.title);

							var srData = reddits[channel][post.subreddit.toLowerCase()];
							var color = srData.color ? srData.color : '01,00';

							if (post.distinguished === 'moderator') {
								post.author = '\x0303' + post.author + '\x03 [\x0303M\x03]';
								post.title = '\x0303' + post.title + '\x03';
							} else if (post.distinguished === 'admin') {
								post.author = '\x0304' + post.author + '\x04 [\x0304A\x03]';
								post.title = '\x0304' + post.title + '\x04';
							}

							var msg = (post.over_18 || srData.nsfl ? '[\x0304NSFW\x03] ' : '')
							+ '[\x03' + color + post.subreddit + '\x03]'
							+ ' [' + post.author + '] '
							+ ent.decode(post.title)
							+ (post.link_flair_text ? (' [' + ent.decode(post.link_flair_text) + ']') : '')
							+ ' [ http://reddit.com/' + post.id + ' ]'
							+ (!post.is_self ? ' [ ' + post.url + ' ]' : '');

							if (!post.is_self) {
								sauce(post.url, function (err, results) {
									var best;

									if (!err && (best = results[0])) {
										shortenURL(best.link, function(err, url) {
											if (url) {
												msg += ' [S: ' + url + ' ]';
											} // else msg stays as is

											client.say(channel, msg);
										});
									} else {
										client.say(channel, msg);
									}
								});
							} else {
								client.say(channel, msg);
							}
						});
Beispiel #7
0
function processBlockquotes(obj){

    var html;
    var return_array = [];

    switch(obj.type){
        case 'photo':
            html = obj.caption;
            break;
        case 'video':
            html = obj.caption;
            break;
        case 'text':
            html = obj.body;
            break;
        case 'link':
            html = obj.description;
            break;
        case 'quote':
            return_array.push( ent.decode( obj.text ) );
            return return_array;
            break;
        default:
            return null;
            html = '';
            break;
    }

    html = ent.decode( html );

    //console.log('HTML!!!');
    //console.log(html);

    var $html = $(html);

    $html.find('blockquote').each(function(i){
        var text = $(this).text();
        return_array.push( text );

        //console.log('******* found blockquote! '+ i + ' with blockquote: '+ text);
    });

    if(return_array.length > 0){
        return return_array;
    }else{
        return null;
    }

}
Beispiel #8
0
util.ApiError = createErrorClass('ApiError', function(errorBody) {
  this.code = errorBody.code;
  this.errors = errorBody.errors;
  this.response = errorBody.response;

  try {
    this.errors = JSON.parse(this.response.body).error.errors;
  } catch (e) {
    this.errors = errorBody.errors;
  }

  const messages = [];

  if (errorBody.message) {
    messages.push(errorBody.message);
  }

  if (this.errors && this.errors.length === 1) {
    messages.push(this.errors[0].message);
  } else if (this.response && this.response.body) {
    messages.push(ent.decode(errorBody.response.body.toString()));
  } else if (!errorBody.message) {
    messages.push('Error during request.');
  }

  this.message = uniq(messages).join(' - ');
});
Beispiel #9
0
      var segments = _.map(result.transcript.text, function(textElement) {

        var text = ent.decode(textElement._).replace('\n', ' ');
        if (text.indexOf(':') !== -1) {
          console.log('THOUGHT SPEAKER!!! (V)');
          console.log(textElement.$);
          text = text.split(':')[1].trim();
          console.log([text]);
        }

        // function remove
        if (text.indexOf('(') !== -1 || text.indexOf(')') !== -1 ||
           text.indexOf('[') !== -1 || text.indexOf(']') !== -1) {
          console.log("CRAP DETECTED!!! Skipping... (V)");
          console.log([text]);
          return null;

      }
        return {
          text: text,
          start: Number(textElement.$.start),
          end: Number(textElement.$.start) + Number(textElement.$.dur),
          dur: Number(textElement.$.dur)
        }
      });
renderer.paragraph = function(text) {
	if (text === '') {
		return '';
	}
	text = ent.decode(text);
	return text + ' ';
};
 var decodeEntities = function (str) {
   // 文字列でない場合(cheerioオブジェクトなど)はそのまま返す
   if (typeof(str) !== 'string') {
     return str;
   }
   return ent.decode(str);
 };
Beispiel #12
0
return robot.respond(/happy(.*)/i, function(msg) {

		//Variables
		var input,regex,city;

		//Strip whitespace and lowercase input
		input = msg.match[1].trim().toLowerCase();

		//Regex for removing specials characters
		regex = /[^\w\s]/gi;
		city = input.replace(regex, "");

		//Use ent to decode any html entities
		city = ent.decode(city);

		//Replace spaces with '-' to work with api request
		city = city.split(' ').join('-');

		//Check for city to not be empty
		if(city !== ""){

			//Call fixCity function to check for api city alterations
			fixCity(msg,city);

		//Send error message if nothing is entered after hubot happy
		}else{
			msg.send("Please enter a city.");
		}

});
function populateArray(a,value,htmlValues){
	htmlValues = htmlValues || false;

	var vStr = '' + value;

	if(value == "tech" || value == "Tech" || value == "TECH"){
		value = "technology";
	}

	if(value != null){//get rid of the IFTTT tags

		if(htmlValues){
			var done = populateInlineImages(vStr);
			vStr = _(vStr).stripTags();		
		}

		vStr = vStr.replace(/,/g, '');//replace all commas with empty string
		vStr = vStr.replace(/\n/g, ' ');//replace all carriage returns with empty string

		vStr = ent.decode( vStr );
		a.push( vStr );
	}else{
		a.push(' ');
	}
	return a;
}
function populateArray(a,value,htmlValues){
	htmlValues = htmlValues || false;

	var vStr = '' + value;

	if(value == "tech" || value == "Tech" || value == "TECH"){
		console.log('value: '+ value);
		value = "Technology";
	}

	if(value != null){//get rid of the IFTTT tags

		if(htmlValues){
			var done = populateInlineImages(vStr);
			vStr = _(vStr).stripTags();		
		}

		vStr = vStr.replace(/,/g, '');//replace all commas with empty string
		vStr = vStr.replace(/\n/g, ' ');//replace all carriage returns with empty string

		vStr = ent.decode( vStr );

		//vStr = _(vStr).prune(500);//trim to 500 characters without cutting words in half

		a.push( vStr );
	}else{
		//console.log('value is: '+value);
		a.push(' ');
	}
	return a;
}
Beispiel #15
0
sleuth.parseResponse = function (response, rnd) {
    var entries     = typeof response.feed === 'object' && response.feed.entry || [];
    
    if (entries && entries.length > 0) {
        var idx     = rnd === true ? ~~(Math.random() * entries.length) : 0;
        var video   = entries[idx];
        var title   = video.title['$t'] ? ent.decode(video.title['$t']) : '';
        var id      = _.last(video.id['$t'].split(':'));
        var rating  = typeof video['gd$rating'] !== 'undefined' ? video['gd$rating'].average.toFixed(2) : '';
        var likes   = typeof video['yt$rating'] !== 'undefined' ? video['yt$rating'].numLikes           : false;
        var views   = 0;
        
        // Bug #108 - don't crash when viewcount is unavailable
        if (typeof video['yt$statistics'] === 'object') {
            views = parseInt(video['yt$statistics'].viewCount, 10);
            
            if (views > 0) {
                views = sleuth.commafy(views);
            }
            
        } else {
            views = "unavailable";
        }
        
        return {
            title      : title,
            viewCount  : views,
            rating     : rating,
            likeCount  : likes > 0 ? sleuth.commafy(likes) : 0,
            id         : id,
            link       : sleuth.getYTLink(id)
        };
    }
};
Beispiel #16
0
					async.eachSeries($('.idm_category_row'), function(that, next) {

						var fileinfo = $(that).find('.file_info').html().match(/([\d,]+)\s+downloads\s+\(([\d,]+)\s+views/i);
						var url = $(that).find('h3.ipsType_subtitle a').attr('href').replace(/s=[a-f\d]+&?/gi, '');
						var dateString = $(that).find('.file_info .date').html().trim().replace(/^added|^updated|,/gi, '').trim();
						var dateParsed = chrono.parse(dateString, today);
						if (dateParsed.length == 0) {
							logger.log('warn', '[vpf] Could not parse date "%s".', dateString);
						}

						var u = url.match(/showfile=(\d+)/i);
						// author dom is different when logged in (names are linked)
						var author = $(that).find('.basic_info .desc').html().match(/by\s+([^\s]+)/i);
						var descr = $(that).find('span[class="desc"]').html();
						if (u) {
							currentResult.push({
								fileId: parseInt(u[1]),
								title: $(that).find('h3.ipsType_subtitle a').attr('title').replace(/^view file named\s+/ig, ''),
								description: descr ? ent.decode(descr).trim() : '',
								downloads: parseInt(fileinfo[1].replace(/,/, '')),
								views: parseInt(fileinfo[2].replace(/,/, '')),
								updated: dateParsed.length > 0 ? dateParsed[0].startDate : null,
								author: author ? author[1] : $(that).find('.___hover___member span').html()
							});
							next();
						} else {
							logger.log('error', 'ERROR: Could not parse file ID from %s.', url);
							next('Could not parse file ID from ' + url);
						}

					}, function() {
Beispiel #17
0
	speakeruids.forEach(function (speakerId) {
		var speaker = speakerMap[eventId + '-speaker-'+speakerId];
		if (speaker != undefined) {
			speakers.push({'id': speaker.id, 'name': ent.decode(speaker.name)});
		} else {
			console.error("unknown speaker " + speakerId);
		}
	})
Beispiel #18
0
Compiler.prototype.visitText = function (text) {
  if (/[<>&]/.test(text.val.replace(/&((#\d+)|#[xX]([A-Fa-f0-9]+)|([^;\W]+));?/g, ''))) {
    throw new Error('Plain Text cannot contain "<" or ">" or "&" in react-jade');
  } else if (text.val.length !== 0) {
    text.val = ent.decode(text.val);
    this.buf.push('tags.push(' + JSON.stringify(text.val) + ')');
  }
};
Beispiel #19
0
 self.htmlToPlaintext = function(html) {
   // The awesomest HTML renderer ever (look out webkit):
   // block element opening tags = newlines, closing tags and non-container tags just gone
   html = html.replace(/<\/.*?\>/g, '');
   html = html.replace(/<(h1|h2|h3|h4|h5|h6|p|br|blockquote|li|article|address|footer|pre|header|table|tr|td|th|tfoot|thead|div|dl|dt|dd).*?\>/gi, '\n');
   html = html.replace(/<.*?\>/g, '');
   return ent.decode(html);
 };
function populateBodyCaption(a,value){
	var valueStr = '' + value;
	if(value != null){//get rid of the IFTTT tags

		
		valueStr = ent.decode( valueStr );
		valueStr = _.trim( valueStr );

		var $html = populateInlineImages(valueStr);//strips out all images and populates the image array, returns html string without img tags

		var html_text = $html.text();

		var paras = html_text.split('\n');

		//remove any empty elements from the array
		for(var j = 0; j < paras.length; j++){
			if((paras[j] == '') || (paras[j].length < 3)){
				paras.splice(j, 1);
			}
		}

		for(var t = 0; t < MAX_BODY_PARAGRAPHS; t++){
			if(paras[t] != undefined){

				//vStr = _(vStr).stripTags();	
				
				paras[t] = paras[t].replace(/,/g, '');//replace all commas with empty string
				paras[t] = paras[t].replace(/,/g, '');//replace all commas with empty string
				paras[t] = paras[t].replace(/—/g, '-');//replace all commas with empty string
				paras[t] = paras[t].replace(/—/g, '-');//replace all commas with empty string
				paras[t] = paras[t].replace(/“/g, '"');//replace all commas with empty string
				paras[t] = paras[t].replace(/”/g, '"');//replace all commas with empty string
				paras[t] = paras[t].replace(/’/g, "'");//replace all commas with empty string
				paras[t] = paras[t].replace(/‘/g, "'");//replace all commas with empty string

				paras[t] = paras[t].replace(/</g, '');//replace all commas with empty string
				paras[t] = paras[t].replace(/>/g, '');//replace all commas with empty string
				paras[t] = paras[t].replace(/&nbsp;/g, ' ');//replace all commas with empty string

				paras[t] = paras[t].replace(/í/g, 'i');//replace all commas with empty string
				paras[t] = paras[t].replace(/•/g, '-');//replace all commas with empty string
				paras[t] = paras[t].replace(/»/g, '');//replace all commas with empty string

				//paras[t] = ent.decode( paras[t] );

				a.push( paras[t] );
			}else{
				a.push(' ');
			}
		}
	}else{
		for(var t = 0; t < MAX_BODY_PARAGRAPHS; t++){
			a.push(' ');
		}
	}
	return a;
}
Beispiel #21
0
        PreviewImages.cropThumbnail(ctx, path, function(err) {
            if (err) {
                return callback(err);
            }

            // Check if we can update the main content metadata (displayName, description, ..)
            var params = {};
            opts = opts || {};
            if (opts.displayName && ctx.content.displayName === ctx.content.link && typeof opts.displayName === 'string') {
                ctx.addContentMetadata('displayName', ent.decode(opts.displayName));
                log().trace({'contentId': ctx.contentId}, 'Updating the content displayName.');
            }
            if (opts.description && !ctx.content.description && typeof opts.description === 'string') {
                ctx.addContentMetadata('description', ent.decode(opts.description));
                log().trace({'contentId': ctx.contentId}, 'Updating the content description.');
            }
            callback();
        });
Beispiel #22
0
 fetch(googleurl, function (error, meta, body) {
     try {
         data = JSON.parse(body.toString());
         output = 'Google Result: ' + data.responseData.results[0]['title'].replace(/<(?:.|\n)*?>/gm, '') + ' - ' + data.responseData.results[0]['url'];
         bot.say(to, ent.decode(output));
     } catch (err) {
         bot.say(to, 'err: ' + err);
     }
 });
    convert: function (node) {

        if (node.type === 'tag') {
            return converter.convertTag(node);
        }
        else if (node.type === 'text') {
            return new VText(decode(node.data));
        }
    },
Beispiel #24
0
				searchAnime(message, function (err, data) {
					if (err) {
						client.say(channel, err);
					} else if (typeof data === 'object') {
						client.say(channel, ent.decode(data.title) + ' (' + (data.episodes ? data.episodes : '?') + ' episodes) - http://myanimelist.net/anime/' + data.id);
					} else {
						client.say(channel, 'Couldn\'t parse anime info, here\'s the link though: http://myanimelist.net/anime/' + data);
					}
				});
Beispiel #25
0
 db.query("SELECT id, "+valid_fields.join(", ")+" FROM homestore_items WHERE id = ?", [id], function(err, rows) {
     if (!rows[0]) return cb({error: "No such item ID "+id+" :("});
     
     var result = ["Updating item ID: "+rows[0].id+"..."];
     
     var up = {};
     
     for (var ii in valid_things) {
         try { 
             data[ ii ] = ent.decode(data[ ii ]);
         } catch(e) {}
         if (data[ ii ]) {
             if (rows[0][ valid_things[ ii ] ] != data[ ii ]) {
                 up[ valid_things[ ii ] ] = data[ ii ];
                 if (!rows[0][ valid_things[ ii ] ]) {
                     result.push("Adding "+ii+": "+data[ ii ]);
                 } else {
                     result.push("Updating "+ii+": "+rows[0][ valid_things[ ii ] ]+" -to- "+data[ ii ]);
                 }
             }
         }
     }
     
     var fields = [];
     var values = [];
     for(var ii in up) {
         fields.push(ii+"=?");
         values.push(up[ ii ]);
     }
     
     if (!fields.length) {
         result.push("Nothing to change.");
         // set to autocompleted though
         db.query("UPDATE homestore_items SET autocompleted = 1 WHERE id = ?", [id]);
         return cb(result);
         //return cb([code+": Nothing to update! :)"]);
     }
     
     values.push(id);
     
     db.query("UPDATE homestore_items SET "+fields.join(", ")+", autocompleted = 1 WHERE id = ?", values, function(err, rows) {
         if (err) {
             return cb({error: err});
         }
         
         if (rows.affectedRows) {
             result.push("Updated item data in database");
         }
         
         cb(result);
         
         // refetch and recache item
         item.get(id, false, function() {});
         
         return;
     });
 });
Beispiel #26
0
function parseValue(value, flag) {
  // 1. HTML decode
  // 2. Quote embed
  if(flag) {
    value = ent.decode(value).replace(/"/g, '""');
    return `"${value}"`;
  }
  return value;
}
Beispiel #27
0
 page = request(link.replace('https', 'http'), function(error, response, body) {
     if(!error && response.statusCode == 200) {
         body = body.replace(/(\r\n|\n\r|\n)/gim, " ");
         var title = body.valMatch(/<title>(.*?)<\/title>/, 2);
         if(title && title.length < 140) {
             callback(ent.decode(title[1]).trim());
         }
     }
 });
Beispiel #28
0
	wsA.on('message', function(message) {
		//console.log(message)
		var pa = JSON.parse(message)[0]; //parse
		var ev = pa[0]; //event名字
		/*
			client_connected, new_message, websocket_rails.ping, update_state
		*/
		if(pa[1]['data']['message']){
			pa[1]['data']['message'] = ent.decode(pa[1]['data']['message']);//html entity
		}
		var msg = pa[1]['data']['message'];
		var sender = pa[1]['data']['sender']; //0 是系統, 1是自己, 2是對方
		var leave = pa[1]['data']['leave']; //若對方leave, 要寄給系統["change_person",{}]
		//console.log(pa[1]['data']['message']);
		if (ev == 'new_message') {
			//console.log(message)
			if( pa[1]['user_id'] ){
				userId_A = pa[1]['user_id'];

				//console.log(message);
			}
			pa[1]['data']['sender'] = 1; //使系統知道是我要傳給對方
			message = JSON.stringify(pa);
			if (sender == 2) {
				//fakePaToB = pa;//取得傳假話參數");
				console.log("A:「 " + msg + " 」");
				//console.log(message);
				//wsB.send(message);
			} else if (!sender && leave) {
				//leave == false 是初始系統提示訊息的時候, 其餘時候都是undefined
				//change person 或 disconnected
				//
				console.log('A 已經離開房間');

				wsA.send(leavecmd);
				//wsB.send(leavecmd);
			}
		} else if (ev == 'update_state') {

			if (pa[1]['data']['typing']) {
				//console.log('A typing...');
			}
			if (pa[1]['data']['last_read']) {
				//console.log('A 已讀');
			}
			//wsB.send(message);


		} else if (ev == 'websocket_rails.ping') {
			a = Randomize();
			wsA.send('["websocket_rails.pong",{"id":' + Randomize() + ',"data":{}}]')
		} else if (ev == 'client_connected') {
			console.log('A 已進入房間')

		}
	});
function measure(text, fontSize = 25) {
  var doc = new PDFDocument();
  doc.font(__dirname + '/../STIXv1.1.1-webfonts/stix-web/STIXGeneral-Italic.ttf')
     .fontSize(fontSize);
  text = ent.decode(text);
  return {
    width: doc.widthOfString(text) + 6,
    height: doc.heightOfString(text)
  };
}
Beispiel #30
0
								fbrequest.get(permal, function(err, httpResponse, body) {
									// fs.writeFileSync('a.html', body);
									var gethidden = body.match(/code class="hidden_elem" id=".+"><!-- (<div.+userContent.+)? --><\/code/);
									// console.log(gethidden[1]);
									$ = cheerio.load(ent.decode(gethidden[1]));
									var content = $('.userContent').text();
									fs.appendFileSync('./name.txt', name + '\t' + uid + '\t' + content + '\n');


								});