Skip to content

Commit

Permalink
added skip uploads flag and fixex broken integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uberfastman committed Oct 18, 2024
1 parent 8e4672c commit 150ca7a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
services:

app:
image: ghcr.io/uberfastman/fantasy-football-metrics-weekly-report:19.2.3
image: ghcr.io/uberfastman/fantasy-football-metrics-weekly-report:19.3.0
platform: linux/amd64
ports:
- "5001:5000"
Expand Down
24 changes: 13 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main(argv):
)

try:
opts, args = getopt.getopt(argv, "hdf:l:w:k:g:y:srp:bqot")
opts, args = getopt.getopt(argv, "hdf:l:w:k:g:y:srp:bqout")
except getopt.GetoptError:
print(usage_str)
sys.exit(2)
Expand Down Expand Up @@ -134,10 +134,12 @@ def main(argv):
options_dict["dq_ce"] = True

# for developers
elif opt in ("-t", "--test"):
options_dict["test"] = True
elif opt in ("-o", "--offline"):
options_dict["offline"] = True
elif opt in ("-u", "--skip-uploads"):
options_dict["offline"] = True
elif opt in ("-t", "--test"):
options_dict["test"] = True

return options_dict

Expand Down Expand Up @@ -309,17 +311,17 @@ def select_week(use_default: bool = False) -> Union[int, None]:

upload_message = ""
if settings.integration_settings.google_drive_upload_bool:
if not options.get("test", False):
if not options.get("skip_uploads", False) and not options.get("test", False):
google_drive_integration = GoogleDriveIntegration(report.league.week_for_report)

# upload PDF to Google Drive
upload_message = google_drive_integration.upload_file(report_pdf)
logger.info(upload_message)
else:
logger.info("Test report NOT uploaded to Google Drive.")
logger.info(f"Report NOT uploaded to Google Drive with options: {options}")

if settings.integration_settings.slack_post_bool:
if not options.get("test", False):
if not options.get("skip_uploads", False) and not options.get("test", False):
slack_integration = SlackIntegration(report.league.week_for_report)

# post PDF or link to PDF to Slack
Expand Down Expand Up @@ -348,10 +350,10 @@ def select_week(use_default: bool = False) -> Union[int, None]:
f"Report {str(report_pdf)} was NOT posted to Slack with error: {slack_response}"
)
else:
logger.info("Test report NOT posted to Slack.")
logger.info(f"Report NOT posted to Slack with options: {options}")

if settings.integration_settings.groupme_post_bool:
if not options.get("test", False):
if not options.get("skip_uploads", False) and not options.get("test", False):
groupme_integration = GroupMeIntegration(report.league.week_for_report)

# post PDF or link to PDF to GroupMe
Expand Down Expand Up @@ -380,10 +382,10 @@ def select_week(use_default: bool = False) -> Union[int, None]:
f"Report {str(report_pdf)} was NOT posted to GroupMe with error: {groupme_response}"
)
else:
logger.info("Test report NOT posted to GroupMe.")
logger.info(f"Report NOT posted to GroupMe with options: {options}")

if settings.integration_settings.discord_post_bool:
if not options.get("test", False):
if not options.get("skip_uploads", False) and not options.get("test", False):
discord_integration = DiscordIntegration(report.league.week_for_report)

# post PDF or link to PDF to Discord
Expand Down Expand Up @@ -413,4 +415,4 @@ def select_week(use_default: bool = False) -> Union[int, None]:
f"Report {str(report_pdf)} was NOT posted to Discord with error: {discord_response}"
)
else:
logger.info("Test report NOT posted to Discord.")
logger.info(f"Report NOT posted to Discord with options: {options}")
16 changes: 12 additions & 4 deletions report/pdf/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,10 +973,18 @@ def create_data_table(self, metric_type: str, col_headers: List[List[str]], data
# truncate data cell contents to specified max characters and half of specified max characters
# if cell is a team manager header
display_row.append(
truncate_cell_for_display(cell, halve_max_chars=(cell_ndx == manager_header_ndx))
truncate_cell_for_display(
cell,
max_chars=settings.report_settings.max_data_chars,
halve_max_chars=(cell_ndx == manager_header_ndx)
)
)
else:
display_row.append(truncate_cell_for_display(cell, sesqui_max_chars=True))
display_row.append(
truncate_cell_for_display(
cell, max_chars=settings.report_settings.max_data_chars, sesqui_max_chars=True
)
)

else:
display_row.append(cell)
Expand Down Expand Up @@ -1005,7 +1013,7 @@ def create_line_chart(self, data: List[Any], data_length: int, series_names: Lis
display_series_names = []
for name in series_names:
# truncate series name to specified max characters
display_series_names.append(truncate_cell_for_display(str(name)))
display_series_names.append(truncate_cell_for_display(str(name), settings.report_settings.max_data_chars))

series_names = display_series_names

Expand Down Expand Up @@ -2057,7 +2065,7 @@ def add_toc_entry(self, title: str, section_key: str, color: Optional[str] = Non

if truncate_title:
title = (
f"{truncate_cell_for_display(title, sesqui_max_chars=True)}"
f"{truncate_cell_for_display(title, settings.report_settings.max_data_chars, sesqui_max_chars=True)}"
f"{f' (Part {team_page})' if team_page else ''}"
)

Expand Down
Binary file modified resources/files/example_report.pdf
Binary file not shown.
5 changes: 2 additions & 3 deletions utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from utilities.constants import player_name_punctuation, player_name_suffixes
from utilities.logger import get_logger
from utilities.settings import settings

logger = get_logger(__name__, propagate=False)

Expand All @@ -14,8 +13,8 @@ def format_platform_display(platform: str) -> str:
return platform.capitalize() if len(platform) > 4 else platform.upper()


def truncate_cell_for_display(cell_text: str, halve_max_chars: bool = False, sesqui_max_chars: bool = False) -> str:
max_chars: int = settings.report_settings.max_data_chars
def truncate_cell_for_display(cell_text: str, max_chars: int, halve_max_chars: bool = False,
sesqui_max_chars: bool = False) -> str:

if halve_max_chars and sesqui_max_chars:
logger.warning(
Expand Down

0 comments on commit 150ca7a

Please sign in to comment.