Cameron Darries
Cameron Darries

Reputation: 1

Building a spam detector in python without the use of third party libraries

def spam_detection(email):
    with open('email.txt', 'r', errors='ignore') as f:
        contents = f.read()

    spam_keywords = ["account has been hacked", "urgent", "save on", "big deals","click this link","win","claim your prize"," !", " .", "lucky winner", "click here",]   

    if any(keyword in contents for keyword in spam_keywords):
        return "spam"

    return "ham"

result = spam_detection('email.txt')
print(result)

#this is my code

I'm trying to flag all emails with the given keywords in the contents and subjects of any given email.

Upvotes: 0

Views: 116

Answers (0)

Related Questions