-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Robota #1
base: master
Are you sure you want to change the base?
Robota #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,48 +3,46 @@ | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commit messages is not clear, I believe that you want to say: |
||
from classes.mail_wrapper import MailWrapper | ||
from classes.imap import ImapGmailWrapper | ||
from classes.types import MailSenderSubject | ||
|
||
from config import mail, app_password, url_telegram, chat_id | ||
|
||
def check_gmail(): | ||
|
||
imap = ImapGmailWrapper(mail, app_password) | ||
imap.select_mail_box('inbox') | ||
possible_new_email_id = int(imap.get_last_email_id('UNSEEN')) | ||
new_email_id = int(imap.get_last_email_id('UNSEEN')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be squashed with 5453374 |
||
|
||
if not os.path.exists('recent_mail.txt'): | ||
save_latest_email_id(possible_new_email_id) | ||
save_latest_email_id(new_email_id) | ||
return | ||
|
||
file_reader = open('recent_mail.txt', 'r') | ||
if file_reader.readable(): | ||
current_mail_id = int(file_reader.read()) | ||
file_reader.close() | ||
|
||
if possible_new_email_id > current_mail_id: | ||
latest_email_id = possible_new_email_id | ||
number_of_new_mails = latest_email_id - current_mail_id | ||
if new_email_id > current_mail_id: | ||
save_latest_email_id(new_email_id) | ||
|
||
file_reader.close() | ||
senders_subjects = [] | ||
message = 'Shalom Adonai, irmãos. Novo(s) e-mail(s), deem uma olhada:\n' | ||
|
||
save_latest_email_id(latest_email_id) | ||
for mail_id in range(current_mail_id + 1, new_email_id + 1): | ||
raw_email = imap.fetchs([mail_id]) | ||
|
||
raw_email = imap.fetchs([latest_email_id]) | ||
mail_parser = MailWrapper(raw_email) | ||
|
||
mail_parser = MailWrapper(raw_email) | ||
sender = mail_parser.get_sender() | ||
senders_subjects.append(MailSenderSubject(mail_parser.get_sender(), mail_parser.get_subject())) | ||
|
||
subject = mail_parser.get_subject() | ||
|
||
if number_of_new_mails > 1: | ||
message = 'Shalom Adonai, irmãos. {} novos emails, deem uma olhada.'.format(number_of_new_mails) | ||
else: | ||
message = 'Shalom Adonai, irmãos. Novo email, deem uma olhada.\n\nTítulo: {}\n\nRemetente: {}'.format(subject, sender) | ||
for sender_subject in senders_subjects: | ||
message += '\nRemetente: {}\nTítulo: {}\n'.format(sender_subject.sender, sender_subject.subject) | ||
|
||
send_message(message) | ||
|
||
def save_latest_email_id(latest_email_id): | ||
def save_latest_email_id(new_email_id): | ||
file_writer = open('recent_mail.txt', 'w') | ||
file_writer.write(str(latest_email_id)) | ||
file_writer.write(str(new_email_id)) | ||
file_writer.close() | ||
|
||
def send_message(message): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually commit messages are don in an imperative format, take a look in https://chris.beams.io/posts/git-commit/