本文代码借鉴了其他人的部分代码,其中的发送邮件功能和艾宾浩斯时间计算功能借用了别人的代码,略微做了一些修改,在此处贴出超链接,需要对自己代码进行修改的请参考:
艾宾浩斯曲线:请搜索以下关键词,不放链接了,太多人原封不动的抄了,尊重原创,如果原创不让我用,联系我删除
python实现“艾宾浩斯”记忆曲线表
邮件发送:https://www.jianshu.com/p/b3d78cf16772,代码直接复制粘贴格式不对,不过还是很有用
如果想要我的考研真题单词的,请自取(百度云):链接:https://pan.baidu.com/s/16khoWUMkyfnIlOd4QI_iYQ 密码:zj3d
这个代码就是一个脚本,想要不间断的运行,要么自己运行在云服务器中,要么自己电脑不关机,哈哈!
也有大佬配置在了个人服务器中,可以自行搜索,以下代码,只需要看注释进行简单的修改即可。
如需转载,请通知我!!!
import random, datetime, time
def word_txt(dir):
with open(dir, encoding='utf-8') as f:
str = f.read()
word = []
for item in str.split('\n')[2:]:
word_list = item.split(' ')
while '' in word_list:
word_list.remove('')
for i in range(0, len(word_list)-1, 2):
word.append({'word': word_list[i], 'meaning': word_list[i+1]})
j = 1
for i in range(0, 1040, 52):
word_now = word[i:i+52]
file_word = "./words/word_{}.txt".format(j)
file_mean = "./words/mean_{}.txt".format(j)
j += 1
with open(file_word, 'w') as f:
for k in range(52):
f.write(word_now[k]['word'] + '\n')
with open(file_mean, 'w') as f:
for n in range(52):
f.write(word_now[n]['word'] + ' ' + word_now[n]['meaning'] + '\n')
def memory():
import time
listnum = 20
wordlist = [[] for i in range(listnum + 1)]
for j in range(1, 5):
t = time.mktime(time.strptime("20 Aug 11 8", "%y %b %d %H"))
t += 60 * 60 * 12 * (j - 1)
for i in [0, 0.5, 1, 2, 4, 8]:
t += 60 * 60 * 24 * i
c = time.ctime(t)
p = time.strptime(c)
s = time.strftime("%Y-%b-%d %H", p)
wordlist[j].append(s)
for j in range(5, 9):
t = time.mktime(time.strptime("20 Aug 15 8", "%y %b %d %H"))
t += 60 * 60 * 12 * (j - 5)
for i in [0, 0.5, 1, 2, 4, 8]:
t += 60 * 60 * 24 * i
c = time.ctime(t)
p = time.strptime(c)
s = time.strftime("%Y-%b-%d %H", p)
wordlist[j].append(s)
for j in range(9, listnum + 1):
t = time.mktime(time.strptime("20 Sep 17 8", "%y %b %d %H"))
t += 60 * 60 * 12 * (j - 5)
for i in [0, 0.5, 1, 2, 4, 8]:
t += 60 * 60 * 24 * i
c = time.ctime(t)
p = time.strptime(c)
s = time.strftime("%Y-%b-%d %H", p)
wordlist[j].append(s)
j = 1
timedict = {}
while j <= listnum:
for listtime in wordlist[j]:
if listtime not in timedict:
timedict[listtime] = [j]
else:
timedict[listtime].append(j)
j += 1
timelist = []
for i in timedict.keys():
t = time.mktime(time.strptime(i, "%Y-%b-%d %H"))
timelist.append(t)
timelist.sort()
for i in range(len(timelist)):
c = time.ctime(timelist[i])
p = time.strptime(c)
s = time.strftime("%Y-%b-%d %H", p)
timelist[i] = s
return timedict, timelist
def email_163(subject,content,files, receive_email):
'''JPNNXVSJNGPROMMP'''
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
sender = ''
passwd = ''
receivers = receive_email
msgRoot = MIMEMultipart()
msgRoot['Subject'] = subject
msgRoot['From'] = sender
if len(receivers) > 1:
msgRoot['To'] = ','.join(receivers)
else:
msgRoot['To'] = receivers[0]
part = MIMEText(content, _charset="utf-8")
msgRoot.attach(part)
for file_name in files:
part = MIMEApplication(open(file_name, 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename=file_name)
msgRoot.attach(part)
try:
s = smtplib.SMTP_SSL('smtp.163.com', 465)
s.login(sender, passwd)
s.sendmail(sender, receivers, msgRoot.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error, 发送失败")
finally:
s.quit()
if __name__ == '__main__':
i = 0
dir = ''
timedict, timelist = memory()
while(1):
word_list = word_txt(dir)
t = time.mktime(time.strptime(timelist[i], "%Y-%b-%d %H"))
now_time = datetime.datetime.now().strftime('%Y-%b-%d %H')
now = time.mktime(time.strptime(str(now_time), "%Y-%b-%d %H"))
if now == t:
subject = '每日单词'
content = '艾宾浩斯曲线单词'
receive_email = ['']
files = []
for item in timedict[now_time]:
files.append('/Users/infinite/PycharmProjects/myProject/scripts/words/mean_{}.txt'.format(item))
files.append('/Users/infinite/PycharmProjects/myProject/scripts/words/word_{}.txt'.format(item))
print(files)
email_163(subject, content, files, receive_email)
i += 1
time.sleep(60)