From 8fe8e465b88e82e4c7e5fcc646384014f283a86e Mon Sep 17 00:00:00 2001 From: Ese <17943860+dlpbc@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:59:55 +0100 Subject: [PATCH] Updated docstring to google format. Updated two scripts from non-google style docstring to google style docstring. --- rctab/daily_routine_tasks.py | 21 ++---- rctab/routers/accounting/send_emails.py | 86 +++++++++---------------- 2 files changed, 37 insertions(+), 70 deletions(-) diff --git a/rctab/daily_routine_tasks.py b/rctab/daily_routine_tasks.py index 78ebd1c..82e2cb4 100644 --- a/rctab/daily_routine_tasks.py +++ b/rctab/daily_routine_tasks.py @@ -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 @@ -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 : list of email addresses of recipients. + since_this_datetime : include information since this date and time, by default None. """ # pylint: disable=invalid-name template_name = "daily_summary.html" @@ -229,10 +224,8 @@ 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. - Returns - ------- - datetime - timestamp of last summary email record in emails table + Returns: + The timestamp of last summary email record in emails table. """ query = ( select([emails]) diff --git a/rctab/routers/accounting/send_emails.py b/rctab/routers/accounting/send_emails.py index 6bfa7da..79cf3c8 100644 --- a/rctab/routers/accounting/send_emails.py +++ b/rctab/routers/accounting/send_emails.py @@ -49,17 +49,12 @@ async def get_sub_email_recipients( ) -> 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 + Args: + database : a database to keep a record of a subscription and its users. + subscription_id : a subscription ID. - Returns - ------- - List[str] - contains email addresses of the users that should receive the email + Returns: + A string that contains email addresses of the users that should receive the email. """ query = get_subscription_details(subscription_id, execute=False) results = await database.fetch_one(query) @@ -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 + 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 - ------- - 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 + 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: @@ -254,12 +239,10 @@ async def send_expiry_looming_emails( ) -> 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 + Args: + database: a database to keep record of subscriptions and of sent emails. + subscription_expiry_dates: a list of subscription ids and expiry dates of + subscriptions nearing expiry. """ # pylint: disable=use-dict-literal email_query = sub_time_based_emails() @@ -293,12 +276,10 @@ async def send_overbudget_emails( ) -> 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 + Args: + database: a database to keep record of subscriptions and of sent emails. + overbudget_subs: a list of subscription ids and percentage of budget used for + subscriptions that exceeded their budget. """ # pylint: disable=use-dict-literal email_query = sub_usage_emails() @@ -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")]) @@ -440,10 +419,8 @@ 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. - Parameters - ---------- - database : Database - holds a record of the subscription, including budget information + Args: + database: a database that holds a record of the subscription, including budget information. """ overbudget_subs = [] @@ -949,12 +926,9 @@ 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 + Args: + template_name : The name of template. + template_data : The data used to render template Returns -------