Skip to content
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

Updated docstring to google format. #12

Merged
merged 5 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions rctab/daily_routine_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ def __exit__(
def datetime_utcnow() -> datetime:
"""Returns the current date and time in the UTC timezone.

Returns
-------
datetime
current UTC date and time
Returns:
The current UTC date and time.
"""
# This can be patched for testing more easily than datetime

Expand Down Expand Up @@ -105,12 +103,9 @@ async def send_summary_email(

Items in the jinja2 template are replaced with those in template_data.

Parameters
----------
recipients : List[str]
list of email addresses of recipients
since_this_datetime : Optional[datetime], optional
include information since this date and time, by default None
Args:
recipients : The email addresses to send summary emails to.
since_this_datetime : Include information since this date and time, by default None.
"""
# pylint: disable=invalid-name
template_name = "daily_summary.html"
Expand Down Expand Up @@ -227,12 +222,10 @@ async def routine_tasks() -> None:


async def get_timestamp_last_summary_email() -> Optional[datetime]:
"""Returns timestamp of the last summary email that has been sent.
"""Retrieve the timestamp from the emails table of the most recent summary email sent.

Returns
-------
datetime
timestamp of last summary email record in emails table
Returns:
The timestamp of the last summary email sent.
"""
query = (
select([emails])
Expand Down
114 changes: 43 additions & 71 deletions rctab/routers/accounting/send_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@
async def get_sub_email_recipients(
database: Database, subscription_id: UUID
) -> List[str]:
"""Returns the users we should email about this subscription.

Parameters
----------
database : Database
a database to keep a record of a subscription and its users
subscription_id : UUID
a subscription ID

Returns
-------
List[str]
contains email addresses of the users that should receive the email
"""Get the email adresses of users that should be emailed about this subscription.

Args:
database : The database recording the subscription and its users.
subscription_id : The ID of the subscription to get user emails for.

Returns:
The email addresses of the users that should receive the email.
"""
query = get_subscription_details(subscription_id, execute=False)
results = await database.fetch_one(query)
Expand Down Expand Up @@ -99,27 +94,17 @@ def send_with_sendgrid(

Items in the jinja2 template are replaced with those in template_data.

Parameters
----------
subject : str
subject of the email
template_name : str
name of jinja2 template used to render the email
template_data : Dict[str, Any]
data passed to the template
to_list : List[str]
contains the email addresses of the recipients

Returns
-------
int
status code that indicates whether or not email was sent sucessfully

Raises
------
MissingEmailParamsError
raises an error if the api key or the "from" email address
is missing
Args:
subject : The subject of the email.
template_name : The name of jinja2 template used to render the email.
template_data : The data passed to the template.
to_list : A string that contains the email addresses of the recipients.

Returns:
The status code that indicates whether or not email was sent sucessfully.

Raises:
MissingEmailParamsError: raises an error if the api key or the "from" email address is missing.
"""
# pylint: disable=invalid-name
try:
Expand Down Expand Up @@ -252,14 +237,12 @@ async def send_expiry_looming_emails(
database: Database,
subscription_expiry_dates: List[Tuple[UUID, date, SubscriptionState]],
) -> None:
"""If needed, sends emails to say that subscription is nearing its expiry date.

Parameters
----------
database : Database
a database to keep record of subscriptions and of sent emails
subscription_expiry_dates : List[Tuple[UUID, date, SubscriptionState]]
subscription ids and expiry dates of subscriptions nearing expiry
"""Send an email to notify users that a subscription is nearing its expiry date.

Args:
database: A database to keep record of subscriptions and of sent emails.
subscription_expiry_dates: A list of subscription ids and expiry dates for
subscriptions nearing expiry.
"""
# pylint: disable=use-dict-literal
email_query = sub_time_based_emails()
Expand Down Expand Up @@ -291,14 +274,12 @@ async def send_overbudget_emails(
database: Database,
overbudget_subs: List[Tuple[UUID, float]],
) -> None:
"""If needed, sends emails to say that subscription is overbudget.

Parameters
----------
database : Database
a database to keep record of subscriptions and of sent emails
overbudget_subs : List[Tuple[UUID, float]]
subscription ids and percentage of budget used for subscriptions that exceeded their budget
"""Send an email to notify users that subscription is overbudget.

Args:
database: The database recording subscriptions and sent emails.
overbudget_subs: A list of subscription ids and the percentage of budget used for
subscriptions that exceeded their budget.
"""
# pylint: disable=use-dict-literal
email_query = sub_usage_emails()
Expand Down Expand Up @@ -328,10 +309,8 @@ async def send_overbudget_emails(
def sub_time_based_emails() -> Select:
"""Builds a query to get the most recent time-based email for each subscription.

Returns
-------
Select
SELECT statement for database query
Returns:
SELECT statement for database query.
"""
most_recent = (
select([func.max_(emails.c.id).label("max_id")])
Expand Down Expand Up @@ -438,12 +417,10 @@ async def check_for_subs_nearing_expiry(database: Database) -> None:


async def check_for_overbudget_subs(database: Database) -> None:
"""Check for subscriptions that should trigger an email as they are overbudget.
"""Check for subscriptions that are overbudget and should trigger an email.

Parameters
----------
database : Database
holds a record of the subscription, including budget information
Args:
database: The database containing a record of the subscription, including budget information.
"""
overbudget_subs = []

Expand Down Expand Up @@ -947,18 +924,13 @@ async def get_approvals_since(


def render_template(template_name: str, template_data: Dict[str, Any]) -> str:
"""Renders html based on provided template and data.

Parameters
----------
template_name : str
name of template
template_data : Dict[str, Any]
data used to render template

Returns
-------
str
"""Renders html based on the provided template and data.

Args:
template_name : The name of template.
template_data : The data used to render the template.

Returns:
The rendered template as a string.
"""
env = Environment(loader=PackageLoader("rctab", "templates/emails"))
Expand Down
Loading