Exemple #1
0
def process_status(status,proc_posts,movies10,music10,args):
	i = args['i']
	scores = args['scores']
	movie_genres = args['movie']
	music_genres = args['music']
	picture = args['pic']
	title=''
	embed=''
	description=''
	score_now = 0
	post_id = status['id']
	if post_id not in proc_posts:
		proc_posts.append(post_id)
	else:
		return proc_posts,movies10,music10
	created = status['updated_time'][:10]

	if 'message' in status:
		message = status['message']
	else:
		message = ''
	if 'comments' in status:
		comments = status['comments']['data']
	else:
		comments = ''
	f_score = 0 #final score
	m_score = analysis.sentiment_analysis(message.encode('utf-8')) #message score
	if m_score >=-0.1:
		f_score +=1
	else:
		f_score -=1
	for c in comments:
		if c['from']['id'] == scores[i]['facebook_id']:
			c_score = 0
			c_score = analysis.sentiment_analysis(c['message'].encode('utf8'))	#comment_score
			if c_score >=-0.1:
				f_score+=1
			else:
				f_score-=1
	if f_score < 0:
		return proc_posts,movies10,music10
	message = re.sub('\n',' ', message)
	message = re.split('[ .,!?]',message)
	message = ' '.join(message[:8])
	results = text_analysis_freebase.getResults(message.encode('utf-8'))
	for entity in results:
		ubuff = 0
		if bool(entity):
			if entity['type'] == 'movie' and entity['genres']:
				for gen in entity['genres']:
					if (gen in movie_genres.keys()):
						ubuff += movie_genres[gen]
				ubuff = float(ubuff)/len(entity['genres'])
				score_now = float(scores[i]['movie_score']['movie_friend_score'])*ubuff
				if score_now > 0:
					title,url,description = youtubeAPI.getVideo(entity)
					if title:
						exist_flag = 0
						for it in movies10:
							if ((post_id == it["post_id"]) and (url == it["embed"])) or url == it["embed"]:
								exist_flag = 1
						if (exist_flag == 0):
							movies10.append({"name":scores[i]['friend_name'],"f_id":scores[i]['facebook_id'],"post_id":post_id,"score":score_now,"message":message.encode('utf-8'),'picture':picture,'title':title,'embed':url,'description':description,'created':created,'genres':entity['genres'],'rated':0})
			elif entity['type'] == 'music' and entity['genres']:
				for key in entity['genres']:
					if key in music_genres.keys():
						ubuff += music_genres[key]
				ubuff = float(ubuff)/len(entity['genres'])
				score_now = float(scores[i]['music_score']['music_friend_score'])*ubuff
				if score_now>0.0:
					title,url,description = youtubeAPI.getVideo(entity)
					if title:
						exist_flag = 0
						for it in music10:
							if ((post_id == it["post_id"]) and (url == it["embed"])) or url == it["embed"]:
								exist_flag = 1
						if exist_flag == 0:
							music10.append({"name":scores[i]['friend_name'],"f_id":scores[i]['facebook_id'],"post_id":post_id,"score":score_now,"message":message.encode('utf-8'),'picture':picture,'title':title,'embed':url,'description':description,'created':created,'genres':entity['genres'],'rated':0})
	return proc_posts,movies10,music10
Exemple #2
0
def process_status(status, proc_posts, movies10, music10, args):
    i = args['i']
    scores = args['scores']
    movie_genres = args['movie']
    music_genres = args['music']
    picture = args['pic']
    title = ''
    embed = ''
    description = ''
    score_now = 0
    post_id = status['id']
    if post_id not in proc_posts:
        proc_posts.append(post_id)
    else:
        return proc_posts, movies10, music10
    created = status['updated_time'][:10]

    if 'message' in status:
        message = status['message']
    else:
        message = ''
    if 'comments' in status:
        comments = status['comments']['data']
    else:
        comments = ''
    f_score = 0  #final score
    m_score = analysis.sentiment_analysis(
        message.encode('utf-8'))  #message score
    if m_score >= -0.1:
        f_score += 1
    else:
        f_score -= 1
    for c in comments:
        if c['from']['id'] == scores[i]['facebook_id']:
            c_score = 0
            c_score = analysis.sentiment_analysis(
                c['message'].encode('utf8'))  #comment_score
            if c_score >= -0.1:
                f_score += 1
            else:
                f_score -= 1
    if f_score < 0:
        return proc_posts, movies10, music10
    message = re.sub('\n', ' ', message)
    message = re.split('[ .,!?]', message)
    message = ' '.join(message[:8])
    results = text_analysis_freebase.getResults(message.encode('utf-8'))
    for entity in results:
        ubuff = 0
        if bool(entity):
            if entity['type'] == 'movie' and entity['genres']:
                for gen in entity['genres']:
                    if (gen in movie_genres.keys()):
                        ubuff += movie_genres[gen]
                ubuff = float(ubuff) / len(entity['genres'])
                score_now = float(
                    scores[i]['movie_score']['movie_friend_score']) * ubuff
                if score_now > 0:
                    title, url, description = youtubeAPI.getVideo(entity)
                    if title:
                        exist_flag = 0
                        for it in movies10:
                            if ((post_id == it["post_id"]) and
                                (url == it["embed"])) or url == it["embed"]:
                                exist_flag = 1
                        if (exist_flag == 0):
                            movies10.append({
                                "name": scores[i]['friend_name'],
                                "f_id": scores[i]['facebook_id'],
                                "post_id": post_id,
                                "score": score_now,
                                "message": message.encode('utf-8'),
                                'picture': picture,
                                'title': title,
                                'embed': url,
                                'description': description,
                                'created': created,
                                'genres': entity['genres'],
                                'rated': 0
                            })
            elif entity['type'] == 'music' and entity['genres']:
                for key in entity['genres']:
                    if key in music_genres.keys():
                        ubuff += music_genres[key]
                ubuff = float(ubuff) / len(entity['genres'])
                score_now = float(
                    scores[i]['music_score']['music_friend_score']) * ubuff
                if score_now > 0.0:
                    title, url, description = youtubeAPI.getVideo(entity)
                    if title:
                        exist_flag = 0
                        for it in music10:
                            if ((post_id == it["post_id"]) and
                                (url == it["embed"])) or url == it["embed"]:
                                exist_flag = 1
                        if exist_flag == 0:
                            music10.append({
                                "name": scores[i]['friend_name'],
                                "f_id": scores[i]['facebook_id'],
                                "post_id": post_id,
                                "score": score_now,
                                "message": message.encode('utf-8'),
                                'picture': picture,
                                'title': title,
                                'embed': url,
                                'description': description,
                                'created': created,
                                'genres': entity['genres'],
                                'rated': 0
                            })
    return proc_posts, movies10, music10
Exemple #3
0
def process_link(link,proc_posts,movies10,music10,args):
	i = args['i']
	scores = args['scores']
	movie_genres = args['movie']
	music_genres = args['music']
	picture = args['pic']
	description = " "
	title = " "
	score_now = 0
	post_id = link['id']
	if post_id not in proc_posts:
		proc_posts.append(post_id)
	else:
		return proc_posts,movies10,music10
	if 'message' in link:
		message = link['message']
	else:
		message = ''
	if 'comments' in link:
		comments = link['comments']['data']
	else:
		comments = ''
	created = link['created_time'][:10]
	if 'name' in link:
		title = link['name']
	if 'description' in link:
		description = link['description']
	plink = link['link']
	if 'youtube' in plink or 'youtu.be' in plink:
		tids,url= youtubeAPI.getEntity(plink,title)
		check = {}
		if bool(tids):
			f_score = 0 #final score
			m_score = analysis.sentiment_analysis(message.encode('utf-8')) #message score
			if m_score >=-0.1:
				f_score +=1
			else:
				f_score -=1
			for c in comments:
				if c['from']['id'] == scores[i]['facebook_id']:
					c_score = 0
					c_score = analysis.sentiment_analysis(c['message'].encode('utf8'))	#comment_score
					if c_score >=-0.1:
						f_score+=1
					else:
						f_score-=1
			if f_score < 0:
				return proc_posts,movies10,music10
			for tid in tids:
				check = text_analysis_freebase.link_search(tid,title)
				if check:
					break
		else:
			return proc_posts,movies10,music10
		entity = check
		if entity:
			ubuff = 0
			if entity['type'] == 'movie' and entity['genres']:
				for gen in entity['genres']:
					if (gen in movie_genres.keys()):
						ubuff += movie_genres[gen]
				ubuff = float(ubuff)/len(entity['genres'])
				score_now = float(scores[i]['movie_score']['movie_friend_score'])*ubuff
				score_now = int(round(score_now,0))
				exist_flag = 0
				for it in movies10:#EDW
					if ((post_id == it["post_id"]) and (url == it["embed"])) or url == it["embed"]:
						exist_flag = 1
				if (exist_flag == 0):
					movies10.append({"name":scores[i]['friend_name'],"f_id":scores[i]['facebook_id'],"post_id":post_id,"score":score_now,"message":message.encode('utf-8'),'link':plink,'picture':picture,"title":title,'description':description,'embed':url,'created':created,'genres':entity['genres'],'rated':0})
			elif entity['type'] == 'music' and entity['genres']:
				for key in entity['genres']:
					if key in music_genres.keys():
						ubuff += music_genres[key]
				ubuff = float(ubuff)/len(entity['genres'])
				score_now = float(scores[i]['music_score']['music_friend_score'])*ubuff
				score_now = int(round(score_now,0))
				exist_flag = 0
				for it in music10:
					if ((post_id == it["post_id"]) and (url == it["embed"])) or url == it["embed"]:
						exist_flag = 1
				if exist_flag == 0:
					music10.append({"name":scores[i]['friend_name'],"f_id":scores[i]['facebook_id'],"post_id":post_id,"score":score_now,"message":message.encode('utf-8'),"link":plink,'picture':picture,"title":title,'description':description,'embed':url,'created':created,'genres':entity['genres'],'rated':0})
	return proc_posts,movies10,music10
Exemple #4
0
def process_link(link, proc_posts, movies10, music10, args):
    i = args['i']
    scores = args['scores']
    movie_genres = args['movie']
    music_genres = args['music']
    picture = args['pic']
    description = " "
    title = " "
    score_now = 0
    post_id = link['id']
    if post_id not in proc_posts:
        proc_posts.append(post_id)
    else:
        return proc_posts, movies10, music10
    if 'message' in link:
        message = link['message']
    else:
        message = ''
    if 'comments' in link:
        comments = link['comments']['data']
    else:
        comments = ''
    created = link['created_time'][:10]
    if 'name' in link:
        title = link['name']
    if 'description' in link:
        description = link['description']
    plink = link['link']
    if 'youtube' in plink or 'youtu.be' in plink:
        tids, url = youtubeAPI.getEntity(plink, title)
        check = {}
        if bool(tids):
            f_score = 0  #final score
            m_score = analysis.sentiment_analysis(
                message.encode('utf-8'))  #message score
            if m_score >= -0.1:
                f_score += 1
            else:
                f_score -= 1
            for c in comments:
                if c['from']['id'] == scores[i]['facebook_id']:
                    c_score = 0
                    c_score = analysis.sentiment_analysis(
                        c['message'].encode('utf8'))  #comment_score
                    if c_score >= -0.1:
                        f_score += 1
                    else:
                        f_score -= 1
            if f_score < 0:
                return proc_posts, movies10, music10
            for tid in tids:
                check = text_analysis_freebase.link_search(tid, title)
                if check:
                    break
        else:
            return proc_posts, movies10, music10
        entity = check
        if entity:
            ubuff = 0
            if entity['type'] == 'movie' and entity['genres']:
                for gen in entity['genres']:
                    if (gen in movie_genres.keys()):
                        ubuff += movie_genres[gen]
                ubuff = float(ubuff) / len(entity['genres'])
                score_now = float(
                    scores[i]['movie_score']['movie_friend_score']) * ubuff
                score_now = int(round(score_now, 0))
                exist_flag = 0
                for it in movies10:  #EDW
                    if ((post_id == it["post_id"]) and
                        (url == it["embed"])) or url == it["embed"]:
                        exist_flag = 1
                if (exist_flag == 0):
                    movies10.append({
                        "name": scores[i]['friend_name'],
                        "f_id": scores[i]['facebook_id'],
                        "post_id": post_id,
                        "score": score_now,
                        "message": message.encode('utf-8'),
                        'link': plink,
                        'picture': picture,
                        "title": title,
                        'description': description,
                        'embed': url,
                        'created': created,
                        'genres': entity['genres'],
                        'rated': 0
                    })
            elif entity['type'] == 'music' and entity['genres']:
                for key in entity['genres']:
                    if key in music_genres.keys():
                        ubuff += music_genres[key]
                ubuff = float(ubuff) / len(entity['genres'])
                score_now = float(
                    scores[i]['music_score']['music_friend_score']) * ubuff
                score_now = int(round(score_now, 0))
                exist_flag = 0
                for it in music10:
                    if ((post_id == it["post_id"]) and
                        (url == it["embed"])) or url == it["embed"]:
                        exist_flag = 1
                if exist_flag == 0:
                    music10.append({
                        "name": scores[i]['friend_name'],
                        "f_id": scores[i]['facebook_id'],
                        "post_id": post_id,
                        "score": score_now,
                        "message": message.encode('utf-8'),
                        "link": plink,
                        'picture': picture,
                        "title": title,
                        'description': description,
                        'embed': url,
                        'created': created,
                        'genres': entity['genres'],
                        'rated': 0
                    })
    return proc_posts, movies10, music10