SMA Exp3
SMA Exp3
ENGINEERING
Experiment No. 03
Semester B.E. Semester VIII – Computer Engineering
Title: Monitor the online reputation of a specific brand by collecting social media
mentions, analyzing the sentiment of these mentions, and identifying the top
influencers discussing the brand.
Description:
The primary goal of this experiment is to monitor the online reputation of a specific brand by collecting
social media mentions, analyzing their sentiment, and identifying key influencers discussing the brand. This
will help in understanding public perception, addressing negative feedback, and leveraging positive
discussions for brand growth.
Methodology:
1. Data Collection:
Use web scraping and APIs (such as Twitter/X API, Facebook Graph API, and Reddit API) to collect
social media mentions related to the brand.
Gather data including text, timestamps, user details, and engagement metrics (likes, shares,
retweets, comments).
2. Preprocessing:
Remove stop words, emojis, special characters, and unnecessary metadata.
Standardize text by converting to lowercase and applying lemmatization or stemming.
3. Sentiment Analysis:
Apply NLP techniques to classify mentions as positive, negative, or neutral.
Use pre-trained models like VADER (for short social texts) or fine-tuned transformer models (BERT,
RoBERTa) for sentiment classification.
4. Influencer Identification:
Rank users based on engagement metrics (follower count, retweets, mentions, replies).
Use network analysis to identify key opinion leaders discussing the brand.
5. Insights and Visualization:
Generate sentiment trend graphs to track reputation over time.
Create a network graph of influencers and their reach.
Identify emerging patterns and topics associated with the brand.
import praw
from textblob import TextBlob
import pandas as pd
CLIENT_ID = 'wR4s22ZsHO85tg5kvqpx7g'
CLIENT_SECRET = 'Ko7OcgyNlmVjupa-OlDaHbTmCwpURA'
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
reddit = praw.Reddit(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
user_agent=USER_AGENT,
check_for_async=False
)
mentions.append({
'type': 'post',
'text': submission.title + " " + submission.selftext,
'author': getattr(submission.author, 'name', 'Deleted'),
'karma': author_karma,
'upvotes': submission.score
})
submission.comments.replace_more(limit=0)
for comment in submission.comments[:comment_limit]:
mentions.append({
'type': 'comment',
'text': comment.body,
'author': getattr(comment.author, 'name', 'Deleted'),
'karma': getattr(comment.author, 'link_karma', 0),
'upvotes': comment.score
})
return mentions
brand_name = "iphone"
mentions = collect_mentions(brand_name, limit=20, comment_limit=3)
df = analyze_sentiment(mentions)
top_contributors = identify_top_contributors(df, top_n=10)
df
Output: