生活随笔
收集整理的這篇文章主要介紹了
利用Python实现每天给自己的邮箱按照艾宾浩斯曲线发送单词
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文代碼借鑒了其他人的部分代碼,其中的發送郵件功能和艾賓浩斯時間計算功能借用了別人的代碼,略微做了一些修改,在此處貼出超鏈接,需要對自己代碼進行修改的請參考:
艾賓浩斯曲線:請搜索以下關鍵詞,不放鏈接了,太多人原封不動的抄了,尊重原創,如果原創不讓我用,聯系我刪除
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
= 1for 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
+= 1with 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 timelistnum
= 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 * ic
= 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 * ic
= 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 * ic
= time
.ctime
(t
)p
= time
.strptime
(c
)s
= time
.strftime
("%Y-%b-%d %H", p
)wordlist
[j
].append
(s
)j
= 1timedict
= {}while j
<= listnum
:for listtime
in wordlist
[j
]:if listtime
not in timedict
:timedict
[listtime
] = [j
]else:timedict
[listtime
].append
(j
)j
+= 1timelist
= []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 MIMEApplicationsender
= '' passwd
= ''receivers
= receive_emailmsgRoot
= MIMEMultipart
()msgRoot
['Subject'] = subjectmsgRoot
['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
= 0dir = '' 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)
總結
以上是生活随笔為你收集整理的利用Python实现每天给自己的邮箱按照艾宾浩斯曲线发送单词的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。