-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
25 lines (19 loc) · 902 Bytes
/
main.py
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
from bs4 import BeautifulSoup
import config
from datetime import datetime, timedelta
from imap_tools import MailBox
def get_mail_since_yesterday():
with MailBox(config.mail_imap).login(config.mail_user, config.mail_passwd, initial_folder='INBOX') as mailbox:
yesterday = (datetime.now().date() - timedelta(days=1)).strftime("%d-%b-%Y")
return [msg for msg in mailbox.fetch(f"SINCE {yesterday}")]
def hh_mail_code():
messages = [msg for msg in get_mail_since_yesterday() if
(msg.subject == 'Код подтверждения' and msg.from_ == '[email protected]')]
if messages:
webpage = messages[len(messages) - 1].html
soup = BeautifulSoup(webpage, "html.parser")
code = soup.select_one(".paragraph > b").text
return code
return 'No recent HH mails since yesterday'
if __name__ == '__main__':
print(hh_mail_code())