当前位置: 首页>>代码示例>>Python>>正文


Python Profile.checkSameTweet方法代码示例

本文整理汇总了Python中profile.Profile.checkSameTweet方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.checkSameTweet方法的具体用法?Python Profile.checkSameTweet怎么用?Python Profile.checkSameTweet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在profile.Profile的用法示例。


在下文中一共展示了Profile.checkSameTweet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: track_fake

# 需要导入模块: from profile import Profile [as 别名]
# 或者: from profile.Profile import checkSameTweet [as 别名]
def track_fake(tweet, directory, filename):
    user = tweet['user']
    fakeness = 0
    most_likely = 7
    likely = 4 
    least_likely = 2
    reasons = 'Reasons: '

    if user['id_str'] not in profiles:
        profile = Profile(user, user['id_str'], user['screen_name'])
        profiles[user['id_str']] = profile
    else:
        profile = profiles[user['id_str']]

    # Check if tweet matches another tweet
    tweetText = tweet['text'].encode('utf-8')
    profile.addTweet(tweetText)
    if profile.checkSameTweet():
        profile.fakeness += 2
        profile.reasons += 'duplicate tweet, '

    #Check if they have a default profile
    if user['default_profile']:
        profile.fakeness += 1
        profile.reasons += 'default, '

    # Check if they have a profile picture
    if user['default_profile_image']:
        profile.fakeness += 2
        profile.reasons += 'egghead, '

    # Check if they have a description
    if user['description'] is None:
        profile.fakeness += 1
        profile.reasons += 'no description, '

    # Check if they follow or 2000 or 2001 users
    if user['friends_count'] == 2000 or user['friends_count'] == 2001:
        profile.fakeness +=  1
        profile.reasons += 'max followings, '

    # Check if they are followed by many people
    if user['followers_count'] == 0:
        profile.fakeness += 2
        profile.reasons += 'no followers, '
    elif user['followers_count'] < 5:
        profile.fakeness += 1

    # A profile is considered fake if the number of fake attributes are greater than the threshold
    # Fake profiles are added to a file
    if profile.fakeness >= most_likely:
        path = directory+MOST_LIKELY_FILE+filename
        with open(path, 'a') as file:
            file.write(str(user['id'])+', '+str(user['screen_name'])+', '+profile.reasons+'\n')
        return True
    elif profile.fakeness >= likely:
        path = directory+LIKELY_FILE+filename
        with open(path, 'a') as file:
            file.write(str(user['id'])+', '+str(user['screen_name'])+', '+profile.reasons+'\n')
        return True
    elif profile.fakeness >= least_likely:
        path = directory+LEAST_LIKELY_FILE+filename
        with open(path, 'a') as file:
            file.write(str(user['id'])+', '+str(user['screen_name'])+', '+profile.reasons+'\n')
        return True
    else:
        return False
开发者ID:Dlarej,项目名称:security-privacy-botnet-project,代码行数:69,代码来源:stream.py


注:本文中的profile.Profile.checkSameTweet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。