Example #1
0
def processHistoryLink(history_posts, user):
    history_movie_entities, history_music_entities = [], []
    ex = datetime.now() - timedelta(days=14)
    for item in history_posts:
        tids = []
        url = ""
        description = ""
        title = ""
        message = ""
        created = item['created_time'][:10]
        if 'name' in item:
            title = item['name']
        plink = item['link']
        post_id = item['id']
        if 'youtube' in plink or 'youtu.be' in plink:
            tids, url = youtubeAPI.getEntity(plink, title)
        check = {}
        if tids:
            for tid in tids:
                check = text_analysis_freebase.link_search(tid, title)
                if check:
                    break
        entity = check
        if entity:
            if entity['type'] == 'movie' and entity['genres']:
                for gen in entity['genres']:
                    if (gen in user['movie_genres'].keys()):
                        user['movie_genres'][gen] += 1
                    else:
                        user['movie_genres'][gen] = 1
                user['movie_categories'].append({
                    'like_name': entity['name'],
                    'fb_id': post_id,
                    'genres': entity['genres']
                })
            elif entity['type'] == 'music' and entity['genres']:
                for key in entity['genres']:
                    if key in user['music_genres'].keys():
                        user['music_genres'][key] += 1
                    else:
                        user['music_genres'][key] = 1
                user['music_categories'].append({
                    'like_name': entity['name'],
                    'fb_id': post_id,
                    'genres': entity['genres']
                })

    return user, history_movie_entities, history_music_entities
Example #2
0
def processHistoryLink(history_posts,user):
	history_movie_entities,history_music_entities = [],[]
	ex = datetime.now() - timedelta(days=14)
	for item in history_posts:
		tids = []
		url = ""
		description = ""
		title = ""
		message = ""
		created = item['created_time'][:10]
		if 'name' in item:
			title = item['name']
		plink = item['link']
		post_id = item['id']
		if 'youtube' in plink or 'youtu.be' in plink:
			tids,url= youtubeAPI.getEntity(plink,title)
		check = {}
		if tids:
			for tid in tids:
				check = text_analysis_freebase.link_search(tid,title)
				if check:
					break
		entity = check
		if entity:
			if entity['type'] == 'movie' and entity['genres']:
				for gen in entity['genres']:
					if (gen in user['movie_genres'].keys()):
						user['movie_genres'][gen] += 1
					else:
						user['movie_genres'][gen] = 1
				user['movie_categories'].append({'like_name':entity['name'],'fb_id':post_id,'genres':entity['genres']})
			elif entity['type'] == 'music' and entity['genres']:
				for key in entity['genres']:
					if key in user['music_genres'].keys():
						user['music_genres'][key] += 1
					else:
						user['music_genres'][key] = 1
				user['music_categories'].append({'like_name':entity['name'],'fb_id':post_id,'genres':entity['genres']})

	return user,history_movie_entities,history_music_entities
Example #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
Example #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