import email, getpass, imaplib, os, re
import matplotlib.pyplot as plt
此目录是保存附件的位置
detach_dir = "F:\OTHERS\CS\PYTHONPROJECTS"
然后,脚本要求用户(或您自己)提供帐户功能
user = raw_input("Enter your GMail username --> ")
pwd = getpass.getpass("Enter your password --> ")
然后连接到gmail imap服务器并登录
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login(user, pwd)
选择一个文件夹,您可以使用整个收件箱
m.select("BUSINESS/PETROLEUM")
应该使用m.list()来获取所有邮箱。搜索来自指定发件人的所有电子邮件,然后
选择邮件标识:
resp, items = m.search(None, '(FROM "EIA_eLists@eia.gov")')
items = items[0].split()
my_msg = [] # store relevant msgs here in please
msg_cnt = 0
break_ = False
我要最后一封邮件,这样我就可以使用items[::-1]
for emailid in items[::-1]:
resp, data = m.fetch(emailid, "(RFC822)")
if ( break_ ):
break
for response_part in data:
if isinstance(response_part, tuple):
msg = email.message_from_string(str(response_part[1]))
varSubject = msg['subject']
varDate = msg['date']
if ( msg_cnt == 100 ):
break_ = True
l = len(my_msg)
US, EastCst, NewEng, CenAtl, LwrAtl, Midwst, GulfCst, RkyMt, WCst, CA =
[0]*l, [0]*l, [0]*l, [0]*l, [0]*l, [0]*l, [0]*l, [0]*l, [0]*l, [0]*l
absc = [k for k in range(len(my_msg))]
dates = [str(msg[1][2])+'-'+str(msg[1][3])+'-'+str(msg[1][0]) for msg in my_msg]
cnt = -1
for msg in my_msg:
data = str(msg[0]).split("\n")
cnt+=1
for c in [k.split("\r")[0] for k in data[2:-2]]:
使用正则表达式获取相关信息
m = re.match( r"(.+)(=3D\$)(.+)" , c )
if( m == None ):
continue
country, na, price = m.groups()
if ( country == "US" or country == "USA" ) :
US[cnt] = float(price)
elif( country == "NewEng" ) :
EastCst[cnt] = float(price)
elif( country == "EastCst" ) :
NewEng[cnt] = float(price)
elif( country == "EastCst" ) :
CenAtl[cnt] = float(price)
elif( country == "EastCst" ) :
LwrAtl[cnt] = float(price)
elif( country == "EastCst" ) :
Midwst[cnt] = float(price)
elif( country == "EastCst" ) :
GulfCst[cnt] = float(price)
elif( country == "EastCst" ) :
RkyMt[cnt] = float(price)
elif( country == "EastCst" ) :
WCst[cnt] = float(price)
elif( country == "EastCst" ) :
CA[cnt] = float(price)
Python
email
库将提供帮助。此目录是保存附件的位置
然后,脚本要求用户(或您自己)提供帐户功能
然后连接到gmail imap服务器并登录
选择一个文件夹,您可以使用整个收件箱
应该使用
m.list()
来获取所有邮箱。搜索来自指定发件人的所有电子邮件,然后 选择邮件标识:我要最后一封邮件,这样我就可以使用
items[::-1]
我只想要那些以
$
开头的我只想要最后100条信息
使用正则表达式获取相关信息
用美国价格绘制所有这些曲线
这里有一些相关的有趣的话题
Get only new emails
Fetch mail body
Forward emails with attachment
Fetch body emails in gmail
结果只针对三个方面
相关问题 更多 >
编程相关推荐