简体   繁体   English

如何创建一个可以确定电子邮件是否为垃圾邮件的 python 程序?

[英]How can I create a python program that can determine whether an email is a spam or not?

I'm new to python, and I want to create a program that can determine whether an email is a spam or not based on three factors.我是 python 新手,我想创建一个程序,可以根据三个因素确定电子邮件是否为垃圾邮件。

The subject (if it's empty, it's spam), the sender (I only want people whose email addresses end with ' .com, ' for example, otherwise it's spam), and the date (I only want emails on non-weekend days, otherwise it's spam).主题(如果为空,则为垃圾邮件)、发件人(我只想要电子邮件地址以“ .com, ”结尾的人,例如,否则为垃圾邮件)和日期(我只想要非周末的电子邮件,否则就是垃圾邮件)。

I did the subject part, and it works successfully.我做了主题部分,它成功地工作了。

The code is attached below.代码附在下面。 But I need help with the sender and the date part.但我需要发件人和日期部分的帮助。

import pandas as pd
ExcelFile = pd.read_excel(r'C:\Users\Email Table.xlsx')
Subject = pd.DataFrame(ExcelFile, columns=['Subject'])

def spam(Subject):
    df_multiindex = ExcelFile.set_index(['Subject'])
    n = len(df_multiindex)
    
    for x in range(n):
        if ((pd.isnull(ExcelFile.loc[x, 'Subject'])) == True):
            print("Spam")
        else:
            print("not spam")

spam(Subject)

You don't provide the format/type of your mail address, so this is just an idea.您没有提供邮件地址的格式/类型,所以这只是一个想法。 Check if the sender address ends with ".com":检查发件人地址是否以“.com”结尾:

if address.endswith(".com"):
    print("Spam")
else:
    print("not spam")

You also do not provide information on how the date is formatted.您也没有提供有关日期格式的信息。 Given a unix timestamp, it'd work like this:给定一个unix时间戳,它会像这样工作:

from datetime import datetime

ts = 1652734079
dt_object = datetime.fromtimestamp(ts)
# Check if weekday is saturday/sunday
if dt_object.weekday() in [5, 6]:
    print("Spam")
else:
    print("not spam")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使程序确定输入是否为python中的int? - How can I make a program determine whether or not the input is an int in python? 使用 Python,如何检测程序是最小化还是最大化? - Using Python, how can I detect whether a program is minimized or maximized? 如何让我的 2 bot 玩家井字游戏程序确定是否为平局? - How can I make my 2 bot player Tic Tac Toe program determine whether it is a draw? 如何在 ssl 中将主题添加到我的 python email 程序中? - How can i add subject to my python email program in ssl? 如何在不分配 IntVar 的情况下确定是否选中了复选按钮? - How can I determine whether a checkbutton is checked without assigning an IntVar? 如何在模板内部确定是否上传了图片? - How can I determine, inside of the template, whether or not an image was uploaded? 如何根据垃圾邮件或非垃圾邮件来区分我的文本? - How can I separate my texts based on spam or not spam? 如何在python程序中创建文件夹系统? - How can I create a folder system inside of my python program? 如何创建一个检查Python可用性的登录程序? - How can I create a login program that checks for availability on Python? 如何在 python 3 中创建考试生成器程序? - How can i create a exam generator program in python 3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM