-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (46 loc) · 1.61 KB
/
main.py
File metadata and controls
56 lines (46 loc) · 1.61 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import logging
import colorama
from core import (
authenticate,
send_emails,
parse_excel_file,
iterate_pandas_rows,
drop_email_duplicates,
compare_save_emails_locally,
DriveAPI,
)
from helper import color_logging
from constants import SUBJECT_FIRST_EMAIL
from saved_tokens import EMAILS_XLSX_ID
logger = logging.getLogger(__name__)
def main():
"""
Authenticates and sends the emails
See: https://developers.google.com/gmail/api/quickstart/python
"""
console = color_logging(level=logging.DEBUG)
logging.basicConfig(
level=logging.DEBUG,
force=True,
handlers=[console],
)
colorama.init(convert=True)
creds = authenticate()
# https://support.google.com/mail/answer/22839?hl=en#zippy=%2Cyou-have-reached-a-limit-for-sending-mail
# You may see this message if you email a total of more than 500 recipients in a single email
# and or more than 500 emails sent in a day.
_input = input("\nAre you sure that you checked that these emails are <=500?\n")
if _input not in ("yes", "Yes", "1", "y", "Y"):
logger.error("Double check the emails!")
return
obj = DriveAPI()
obj.download_file(file_id=EMAILS_XLSX_ID, file_name="emails.xlsx")
excel_file_emails = parse_excel_file()
excel_file_emails = drop_email_duplicates(df=excel_file_emails)
excel_file_emails = compare_save_emails_locally(
df=excel_file_emails, excel_name="emails_sent.xlsx"
)
it = iterate_pandas_rows(df=excel_file_emails)
send_emails(creds=creds, it=it, subject=SUBJECT_FIRST_EMAIL)
if __name__ == "__main__":
main()