一个小东西——单词分类+自动Email

在用百词斩记单词时,有个想法,将自己不熟悉的单词放到手机,有空时就看看加深印象。

1.单词分类 结尾为*的为上一天的单词,结尾为&的为当天的单词,以上两种都是不熟悉的单词。将这两种单词筛选出来,并打印到文件。文件名为月日(4个数字)。

2.将文件发送到邮箱。用python实现。

*不知道为什么用163邮箱总是有问题,最后放弃,改用foxmail邮箱。

 

#include<bits/stdc++.h>
using namespace std;
char IN[10],OUT[10];
int main()
{
    time_t now = time(0);
    tm *it = localtime(&now);
    int mon = it->tm_mon+1;
    int day = it->tm_mday;

    string str1,str2;
	string tempstr;
	tempstr=to_string(mon*100+day);
	cout<<tempstr<<endl;

	str1="in/"+to_string(mon*100+day+10000).substr(1,4)+".txt"+"";
	str2="out"+str1.substr(2,5)+"out"+str1.substr(7);
	cout<<str1<<" "<<str2<<endl;

    strcpy(OUT,str2.c_str());
    strcpy(IN,str1.c_str());


    cout<<"today is "<<str1.substr(3,4)<<endl;

    cout<<"input file name and path:\n"<<IN<<endl;

    cout<<"output file name and path:\n"<<OUT<<endl;

    freopen(IN,"r",stdin);
    string s[1000];
    int cont =0;
    char str[100];
    while(gets(str))
    {
        s[cont++]=str;
    }
    //sort(s,s+cont);
    freopen(OUT,"w",stdout);
    for(int i=0;i<cont;i++)
    {
        int len=s[i].length();
        char temp=s[i][len-1];
        if(temp=='&'||temp=='*')
        {
            cout<<s[i].substr(0,len-1)+" "+s[i].substr(len-1)<<endl;
        }
    }
    return 0;
}

 python发邮件脚本

# -*- coding: cp936 -*-

import datetime
day = int(datetime.datetime.now().day)
month = int(datetime.datetime.now().month)
str = str(day+month*100+10000)
str= str[1:5]
str='out/'+str+'out.txt'
#str为将要Email的文件路径+文件名


import smtplib
#smtplib这个模块是管发邮件
from email.mime.text import MIMEText
#构造邮件内容
from email.mime.multipart import MIMEMultipart
#发带附件的邮件用的
email_host = 'smtp.qq.com'     #邮箱服务器地址
email_user = 'xxx@foxmail.com'  # 发送者账号
email_pwd = '授权码'
# 发送者密码是邮箱的授权码,不是登录的密码
maillist = 'xxx@163.com'
#收件人邮箱,多个账号的话,用逗号隔开
new_msg = MIMEMultipart()
#构建了一个能发附件的邮件对象
new_msg.attach(MIMEText('单词'+str[4:],'plain','gbk'))
# 邮件内容
new_msg['Subject'] = '单词'    # 邮件主题
new_msg['From'] = email_user    # 发送者账号
new_msg['To'] = maillist    # 接收者账号列表
att = MIMEText(open(str).read())
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename='+str[4:]
new_msg.attach(att)
smtp = smtplib.SMTP_SSL(email_host,465) # 连接邮箱,传入邮箱地址,和端口号,smtp的端口号是465
smtp.connect(email_host)
smtp.login(email_user,email_pwd) # 发送者的邮箱账号,密码
smtp.sendmail(email_user, maillist, new_msg.as_string())
# 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
smtp.quit() # 发送完毕后退出smtp
print ('email send success.')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值