-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetcode.py
More file actions
33 lines (31 loc) · 1.04 KB
/
getcode.py
File metadata and controls
33 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import imaplib
import email
import re
import asyncio
async def getcode(id,pw):
#todo 시간 확인해서
await asyncio.sleep(1.0)
userid=id
userpass=pw
server = imaplib.IMAP4_SSL('imap.naver.com')
server.login(userid,userpass)
rv, data = server.select()
rv,data=server.search(None,"(UNSEEN)",'FROM','no-reply@dgist.ac.kr')
data=data[0].split()
recent_no = data[-1]
print(data)
rv, fetched = server.fetch(recent_no, '(RFC822)')
message = email.message_from_bytes(fetched[0][1])
if message.is_multipart():
for part in message.walk():
ctype = part.get_content_type()
cdispo = str(part.get('Content-Disposition'))
if ctype == 'text/plain' and 'attachment' not in cdispo:
body = part.get_payload(decode=True) # decode
break
else:
body = message.get_payload(decode=True)
pattern=re.compile("<span>([0-9]{6})</span>")
match=pattern.search(body.decode('utf-8'))
print(match.group(1))
return match.group(1)