Example #1
0
def troll_bot_analyzer(user, api):
    try:
        user_data = data_user(user, api)
    except tweepy.TweepError:
        logging.error("This user is protected or does not exist. His  information cannot be accessed")
    else:
        if len(user_data["tweets"]) == 0:
            logging.error("There is not enough information to classify this user")
            return False
        hashtags_per_tweet = float(user_data["number_hashtags"]) / len(user_data["tweets"])
        mentions_per_tweet = float(user_data["number_mentions"]) / len(user_data["tweets"])
        percentage_tweet_with_mention = float(user_data["tweet_with_mentions"]) / len(user_data["tweets"])
        percentage_tweet_with_hashtag = float(user_data["tweets_with_hashtags"]) / len(user_data["tweets"])
        signs_per_char, capitals_per_char, activity, percentage_tweet_with_omg = drama_queen(user_data)
        periodicity, answer = periodicity_answer(user_data)
        diversity_hashtags = tweet_iteration_hashtags(user_data)
        diversity_tweets = tweet_iteration_stemming(user_data)
        urls_percentage = tweet_iteration_urls(user_data)
        num_stalker, who_stalker = stalker(user_data)
        per_drama_queen = percentage_drama_queen(activity, percentage_tweet_with_omg, capitals_per_char, signs_per_char,
                                                 percentage_tweet_with_hashtag, percentage_tweet_with_mention,
                                                 mentions_per_tweet, hashtags_per_tweet)
        per_bot = percentage_bot(periodicity, answer, diversity_tweets)
        per_stalker, famous, non_famous = percentage_stalker(num_stalker, who_stalker, mentions_per_tweet, percentage_tweet_with_mention, api)
        if per_stalker == 0:
            per_stalker = num_stalker
        per_spammer = percentage_spammer(diversity_tweets, diversity_hashtags, urls_percentage)
        per_hater = (1 - sentiment(user_data)) * 100

        max_value = [per_bot, per_drama_queen, per_stalker, per_hater, per_spammer]
        index = max_value.index(max(max_value))
        labels = ["bot", "drama_queen", "stalker", "hater", "spammer"]
        final = labels[index]

        return {"user_id": user, "bot": per_bot, "drama_queen": per_drama_queen, "stalker": per_stalker, "hater": per_hater, "spammer": per_spammer, "famous": famous, "non_famous": non_famous, "stalked": who_stalker, "final": final}
Example #2
0
def process_cursor(cursor):
    for user in cursor:

        ans_period, ans_percent = periodicity_answer(user)
        signs, capitals, activity, omg = drama_queen(user)

        new_user = {
            "account_name": user["user"],
            "account_old": user["days_account"],
            "account_desc": user["user_json"]["description"],
            "account_mentions": user["number_mentions"],
            "account_hashtags": user["number_hashtags"],
            "account_language": user["user_json"]["lang"],
            "account_followers": user["user_json"]["followers_count"],
            "account_followees": user["user_json"]["friends_count"],
            "account_geo": user["user_json"]["geo_enabled"],
            "account_location": user["user_json"]["location"],
            "account_total_tweets": user["user_json"]["statuses_count"],
            "account_verified": user["user_json"]["verified"],
            "tweet_period": ans_period,
            "tweet_signs": signs,
            "tweet_capitals": capitals,
            "tweet_activity": activity,
            "tweet_omg": omg,
            "tweet_steeming": tweet_iteration_stemming(user),
            "tweet_hashtags": tweet_iteration_hashtags(user),
            "tweets_with_hashtags": user["tweets_with_hashtags"],
            "tweets_positive": sentiment(user),
            "answer_percent": ans_percent,
        }

        table.upsert(new_user)
Example #3
0
def process_cursor(cursor):
    for user in cursor:

        ans_period, ans_percent = periodicity_answer(user)
        signs, capitals, activity, omg = drama_queen(user)

        new_user = {
            "account_name": user["user"],
            "account_old": user["days_account"],
            "account_desc": user["user_json"]["description"],
            "account_mentions": user["number_mentions"],
            "account_hashtags": user["number_hashtags"],
            "account_language": user["user_json"]["lang"],
            "account_followers": user["user_json"]["followers_count"],
            "account_followees": user["user_json"]["friends_count"],
            "account_geo": user["user_json"]["geo_enabled"],
            "account_location": user["user_json"]["location"],
            "account_total_tweets": user["user_json"]["statuses_count"],
            "account_verified": user["user_json"]["verified"],
            "tweet_period": ans_period,
            "tweet_signs": signs,
            "tweet_capitals": capitals,
            "tweet_activity": activity,
            "tweet_omg": omg,
            "tweet_steeming": tweet_iteration_stemming(user),
            "tweet_hashtags": tweet_iteration_hashtags(user),
            "tweets_with_hashtags": user["tweets_with_hashtags"],
            "tweets_positive": sentiment(user),
            "answer_percent": ans_percent
        }

        table.upsert(new_user)
Example #4
0
def troll_bot_analyzer(user, api):
    try:
        user_data = data_user(user, api)
    except tweepy.TweepError:
        logging.error(
            "This user is protected or does not exist. His  information cannot be accessed"
        )
    else:
        if len(user_data["tweets"]) == 0:
            logging.error(
                "There is not enough information to classify this user")
            return False
        hashtags_per_tweet = float(user_data["number_hashtags"]) / len(
            user_data["tweets"])
        mentions_per_tweet = float(user_data["number_mentions"]) / len(
            user_data["tweets"])
        percentage_tweet_with_mention = float(
            user_data["tweet_with_mentions"]) / len(user_data["tweets"])
        percentage_tweet_with_hashtag = float(
            user_data["tweets_with_hashtags"]) / len(user_data["tweets"])
        signs_per_char, capitals_per_char, activity, percentage_tweet_with_omg = drama_queen(
            user_data)
        periodicity, answer = periodicity_answer(user_data)
        diversity_hashtags = tweet_iteration_hashtags(user_data)
        diversity_tweets = tweet_iteration_stemming(user_data)
        urls_percentage = tweet_iteration_urls(user_data)
        num_stalker, who_stalker = stalker(user_data)
        per_drama_queen = percentage_drama_queen(
            activity, percentage_tweet_with_omg, capitals_per_char,
            signs_per_char, percentage_tweet_with_hashtag,
            percentage_tweet_with_mention, mentions_per_tweet,
            hashtags_per_tweet)
        per_bot = percentage_bot(periodicity, answer, diversity_tweets)
        per_stalker, famous, non_famous = percentage_stalker(
            num_stalker, who_stalker, mentions_per_tweet,
            percentage_tweet_with_mention, api)
        if per_stalker == 0:
            per_stalker = num_stalker
        per_spammer = percentage_spammer(diversity_tweets, diversity_hashtags,
                                         urls_percentage)
        per_hater = (1 - sentiment(user_data)) * 100

        max_value = [
            per_bot, per_drama_queen, per_stalker, per_hater, per_spammer
        ]
        index = max_value.index(max(max_value))
        labels = ["bot", "drama_queen", "stalker", "hater", "spammer"]
        final = labels[index]

        return {
            "user_id": user,
            "bot": per_bot,
            "drama_queen": per_drama_queen,
            "stalker": per_stalker,
            "hater": per_hater,
            "spammer": per_spammer,
            "famous": famous,
            "non_famous": non_famous,
            "stalked": who_stalker,
            "final": final
        }