예제 #1
0
파일: main.py 프로젝트: fura-ness/spambot
def check_for_spammers(authordb, r):

    for author in get_newest_posters(r):

        saved_author = str(author.name) in authordb

        if saved_author:
            author = authordb.get(str(author.name))
        else:
            created = author.created
            author = Author(author)
            author.created = created
            authordb[str(author.username)] = author

        author.seen_at = datetime.datetime.now()

        print '+++ %s%s:' % (author.username,
                             ' (seen)' if saved_author else ''),

        if saved_author and author.possible_spammer == False:
            print '%s has been seen already and cannot be a spammer (%s)' % (
                author.username, author.stats())
            continue

        confidence, spam_profile = author.get_spammer_confidence(r)

        if confidence > 0.5:
            print "%s IS A SPAMMER: %s (%s)" % (author.username, confidence,
                                                author.stats())
            try:
                author.submit(r)
            except Exception as e:
                print 'EXCEPTION', type(e)
                print str(e)

            with open('spammers/%s' % author.username, 'a') as f:
                f.write('%s|%s|%s\n' %
                        (spam_profile.link_karma, spam_profile.comment_karma,
                         spam_profile.domains))

        elif confidence == 0.5:
            print "%s is a POSSIBLE spammer: %s (%s)" % (
                author.username, confidence, author.stats())
            with open('possible-spammers.txt', 'a') as f:
                f.write('http://www.reddit.com/user/%s\n' % author.username)

        elif confidence < 0.5:
            print 'not a spammer (%s)' % author.stats()