-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pylint suggestions, docstrings
- Loading branch information
1 parent
91a6b20
commit 2845484
Showing
7 changed files
with
262 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# auto_mail_sender | ||
App for sending e-mail with remiders about books return deadlines | ||
|
||
Create .env file in main directory. Copy and paste below template: | ||
FIRST_NAME='your name | ||
LAST_NAME='your last name' | ||
EMAIL='your mail' | ||
PASSWORD='password to your mail' | ||
SMTP_SERVER='smtp server name' | ||
PORT='port to your server' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
''' | ||
Main module to start app | ||
''' | ||
import sqlite3 | ||
|
||
from mail_sender import MailSender | ||
from database.db_service import DbManager, DataBaseService | ||
from database.db_service import DataBaseService | ||
from templates.template_render import EmailTemplates | ||
|
||
connection = sqlite3.connect('database/sample_books.db') | ||
|
||
data = DataBaseService(connection) | ||
templates = EmailTemplates() | ||
borrowers_list = data.get_borrowed_books_by_today() | ||
print(borrowers_list) | ||
|
||
email = MailSender(borrowers_list, templates) | ||
email.send_passed_return_date() | ||
choice = input('What would you like to do?\n' | ||
'Press button:\n' | ||
'1 - Send overdue notifications\n' | ||
'2 - Send nearby notifications\n' | ||
'3 - Exit') | ||
|
||
if choice == '1': | ||
email = MailSender(templates, data) | ||
email.send_passed_return_date() | ||
elif choice == '2': | ||
email = MailSender(templates, data) | ||
email.send_incoming_return_date() | ||
else: | ||
print('Wrong button\nStart again!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,82 @@ | ||
""" | ||
This modul maintain messages used in mail_sender.py module. | ||
Python email.message library is used here | ||
In the future there should be jinja2 templates. | ||
""" | ||
|
||
from email.message import EmailMessage | ||
from string import Template | ||
|
||
|
||
class EmailTemplates(): | ||
""" | ||
Class that maintan messages for following scenario: | ||
1. Somebody passed the date of return | ||
2. Someone's return date is later than today. | ||
""" | ||
@staticmethod | ||
def send_reminder_overdue(): | ||
# mssg = Template('$name, You have borrowed $title and return date passed $return_at\n Please return it imidietly\nBest Regards\nPawel') | ||
# return mssg | ||
# message = EmailMessage() | ||
# message.add_header('From', f'{sender}') | ||
# message.add_header('To', f'{borrower.email}') | ||
# message.add_header('Subject', 'Book return reminder') | ||
# body = f''' | ||
# Dear {borrower.name}, | ||
# | ||
# You have borrowed {borrower.title} and return date passed {result}. | ||
# Please return it imidietly. | ||
# | ||
# Best Regards | ||
# Pawel | ||
# ''' | ||
# message.set_content(body) | ||
# message_as_string = message.as_string() | ||
|
||
mssg = Template(''' | ||
... From: $sender_mail | ||
... To: $borrower_email | ||
... Subject: Book return reminder | ||
... Dear $name, You have borrowed $title and return date passed $return_at | ||
... Please return it imidietly. | ||
def send_reminder_overdue(sender_mail, borrower_email, name, title, return_at, subject): | ||
|
||
""" | ||
The send_reminder_overdue function takes in the following arguments: | ||
sender_mail - a string representing the email address of the sender | ||
borrower_email - a string representing | ||
the email address of who borrowed an item from you | ||
name - a string representing their name (first or last) | ||
title - a string representing what they borrowed from you | ||
return_at - an integer that represents when they should have returned it to you by now. | ||
:param sender_mail: Set the sender's email address | ||
:param borrower_email: Send the email to a specific person | ||
:param name: Personalize the message | ||
:param title: Specify the title of the book | ||
:param return_at: Pass the date when the book should be returned | ||
:param subject: Set the subject of the email | ||
:return: A message object | ||
:doc-author: Trelent | ||
""" | ||
mssg = EmailMessage() | ||
mssg.set_content(f''' | ||
Dear {name}, | ||
... Best Regards | ||
... Pawel ''') | ||
You have borrowed {title} and return date passed {return_at}. | ||
Please return it immediately. | ||
Best Regards, | ||
Pawel''') | ||
mssg["Subject"] = subject | ||
mssg["From"] = sender_mail | ||
mssg["To"] = borrower_email | ||
|
||
return mssg | ||
|
||
@staticmethod | ||
def send_reminder_nearby(sender_mail, borrower_email, name, title, return_at, subject): | ||
|
||
""" | ||
The send_reminder_nearby function sends an email to the borrower of a book that is due soon. | ||
The function takes in the following arguments: | ||
sender_mail (str): The email address of the person sending this reminder. | ||
borrower_email (str): The email address of the person who borrowed this book. | ||
name (str): The first name of the person who borrowed this book, | ||
for personalization purposes. | ||
This should be retrieved from your database using SQLAlchemy's query functionality! | ||
:param sender_mail: Set the sender's email address | ||
:param borrower_email: Send the email to the borrower | ||
:param name: Personalize the message | ||
:param title: Specify the title of the book that is borrowed | ||
:param return_at: Get the return date of a book | ||
:param subject: Set the subject of the email | ||
:return: The mssg variable | ||
:doc-author: Trelent | ||
""" | ||
mssg = EmailMessage() | ||
mssg.set_content(f''' | ||
Dear {name}, You have borrowed {title} and return date is {return_at} | ||
Please remember to return it on time. | ||
Best Regards | ||
Pawel ''') | ||
mssg["Subject"] = subject | ||
mssg["From"] = sender_mail | ||
mssg["To"] = borrower_email | ||
|
||
return mssg | ||
# @staticmethod | ||
# def send_reminder_nearby(): | ||
# # mssg = Template('$name, You have borrowed $title and the return day is $return_at. Its about @result days from today.Please try not to overdue this dateBest Regards' | ||
# # 'Pawel') | ||
# # return mssg | ||
# mssg = Template('''\ | ||
# ... From: $sender_mail | ||
# ... Subject: Book return reminder | ||
# ... | ||
# ... $name, You have borrowed $title and return date will pass $return_at\n Its about $result days from today.Please try not to overdue this dateBest Regards ''') | ||
# return mssg |
Oops, something went wrong.