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

Make SMS formatting better for mobile #1

Merged
merged 15 commits into from
Jan 21, 2024
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
15 changes: 6 additions & 9 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
name: Python Testing

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
on: [push, pull_request]

jobs:
Linting:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand All @@ -24,14 +20,15 @@ jobs:
- name: Analysing the code with Flake8
run: |
. ./pdt activate 1>/dev/null && python-lint

Unit_Tests:
needs: Linting
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/security-check.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: Security Check

on: [push]
on: [push, pull_request]

jobs:
Security_Report:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: 3.8
python-version: ${{ matrix.python-version }}
- name: Set up venv
run: |
. ./pdt configure-venv
Expand Down
16 changes: 14 additions & 2 deletions README_DIR/SUPPPORTING_CAST_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* [common/misc.py](#commonmiscpy)
* [records/](#data_access_layerrecords)

This is not an exhaustive view of the `support/` directory. Instead, it just aims to provide clarity on the not immediately obvious or larger files.

#### __common/logger.py__
This module sets up a logger from the logging library in a very particular way.
Using the logging library allows us to send out logs at different levels, then for certain purposes we can pay attention only to specific levels depending on how much detail we want. So, anything at level `INFO` or higher will go to the console output, whilst anything at `DEBUG` or higher will go to a much more detailed .log file where it can be reviewed in case of a crash.
Expand Down Expand Up @@ -42,3 +40,17 @@ Which has lots of functions which provide ways of querying the data in DynamoDB.


* [data_access_layer/](../app/support/data_access_layer/)

#### __find_reminders.py__
This is a nice and simple module.
All it does is find records for which you should get a reminder out of the lambdas.
* [find_reminders.py](../app/support/find_reminders.py)

#### __notifications.py__
This module is all about sending notifications and formatting those notifications.
* [notifications.py](../app/support/notifications.py)

#### __record_formatting.py__
This module houses the RecordFormatter class.
This class is responsible for all record formatting. You can format into a style which suits emails or SMS messages. You can dictate certain aspects of the formatting style by setting variables in the class.
* [record_formatting.py](../app/support/record_formatting.py)
6 changes: 4 additions & 2 deletions app/local_use/basic_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
get_all_records_of_medicine_in_next_due_timeframe
)
from app.support.data_access_layer.records.pet_table_models import RecordType
from app.support.record_formatting import record_formatter
from app.support.record_formatting import RecordFormatter

logger = get_full_logger()

Expand Down Expand Up @@ -100,7 +100,9 @@ def main():
else:
logger.info("Invalid choice!")
exit(1)
logger.info(record_formatter(records=records))

rf = RecordFormatter()
logger.info(rf.format_records(records=records))


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions app/support/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def utc_datetime_now() -> datetime:


def british_format_time(timestamp: float) -> str:
# Gives format in the style: Friday, 24 November 2023 - 05:35PM
"""Gives format in the style: Friday, 24 November 2023 - 05:35PM"""
if not isinstance(timestamp, float):
timestamp = float(timestamp) # Don't error catch, what's the alternative?
return datetime.fromtimestamp(timestamp).strftime('%A, %-d %B %Y - %I:%M %p')


def current_date() -> str:
# Gives format in the style: Friday, 24 November 2023
"""Gives format in the style: Friday, 24 November 2023"""
current_date = utc_datetime_now().date()
return current_date.strftime('%A, %-d %B %Y')

Expand Down
28 changes: 15 additions & 13 deletions app/support/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
get_daily_reminder_topic
)
from support.common.logger import get_full_logger
from support.record_formatting import record_formatter, DIVIDER
from support.record_formatting import RecordFormatter, RecordStyle
from support.common.misc import current_date


Expand Down Expand Up @@ -47,16 +47,6 @@ def _publish_to_topic(topic: Any, message: str, subject: Optional[str] = None):
"""


def _format_reminders(records: List[Dict]):

if len(records) == 0:
reminders = 'There are no reminders for this period.'
else:
reminders = record_formatter(records)
reminders += DIVIDER
return reminders


def format_reminder_email(records: List[Dict], timespan: timedelta) -> Tuple[str, str]:
"""
returns -> (subject, message)
Expand All @@ -68,7 +58,12 @@ def format_reminder_email(records: List[Dict], timespan: timedelta) -> Tuple[str
These are your reminders for this period:

"""
message += _format_reminders(records=records)
if len(records) == 0:
reminders = 'There are no reminders for this period.'
else:
rf = RecordFormatter()
reminders = rf.format_records(records=records)
message += reminders
message += message_sign_off
return subject, message

Expand All @@ -79,6 +74,13 @@ def format_reminder_sms(records: List[Dict], timespan: timedelta) -> str:
These are your reminders for {timespan.days} days, from {current_date()}:

"""
message += _format_reminders(records=records)
if len(records) == 0:
reminders = 'There are no reminders for this period.'
else:
rf = RecordFormatter()
rf.style = RecordStyle.SMS
rf.column_width = 35
reminders = rf.format_records(records=records)
message += reminders
message += message_sign_off
return message
Loading