Skip to content

Commit 2e31ba6

Browse files
authored
Merge pull request #210 from djotaku/output_improvements
Output improvements
2 parents bdeb070 + 2e6232b commit 2e31ba6

File tree

8 files changed

+38
-41
lines changed

8 files changed

+38
-41
lines changed

.github/workflows/linttest.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v1
12-
- name: Set up Python 3.10.8
12+
- name: Set up Python 3.11.2
1313
uses: actions/setup-python@v1
1414
with:
15-
python-version: 3.10.8
15+
python-version: 3.11.2
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install --upgrade pip

.github/workflows/windowsbuild.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v1
12-
- name: Set up Python 3.10.8
12+
- name: Set up Python 3.11.2
1313
uses: actions/setup-python@v1
1414
with:
15-
python-version: 3.10.8
15+
python-version: 3.11.2
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install --upgrade pip

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v3.2.0
5+
rev: v4.4.0
66
hooks:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
- id: check-added-large-files
1111
- repo: https://github.com/PyCQA/isort
12-
rev: 5.10.1
12+
rev: 5.12.0
1313
hooks:
1414
- id: isort
1515
name: isort (python)
1616
- repo: https://github.com/asottile/pyupgrade
17-
rev: v3.2.2
17+
rev: v3.3.1
1818
hooks:
1919
- id: pyupgrade

eldonationtracker/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
__version__ = "7.4.10"
3+
__version__ = "7.5.0"
44

55
base_api_url: str = "https://www.extra-life.org/api"
66
api_version_suffix: str = "?version=1.2"

eldonationtracker/api/participant.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ def output_milestone_data(self) -> None: # pragma: no cover
108108
for milestone in self.milestones
109109
if milestone.is_complete
110110
}
111+
latest_milestone_output = "No Milestones reached yet"
112+
# this should end up with the highest milestone that is completed being output to the file.
113+
for milestone in self.milestones:
114+
if milestone.is_complete:
115+
latest_milestone_output = f"{milestone.fundraising_goal}: Achievement Unlocked: {milestone.description}"
111116
self.write_text_files(milestone_output)
117+
self.write_text_files({"latest_milestone": latest_milestone_output})
112118

113119
def output_incentive_data(self) -> None: # pragma: no cover
114120
"""Write out the incentive data to a text file."""
@@ -155,7 +161,7 @@ def run(self) -> None:
155161
self.output_activities()
156162
# Below is protection against a situation where the API is unavailable.
157163
# Prevents bad data being written to the participant output. Based on the assumption that it would
158-
# absurd to have a goal of $0.
164+
# be absurd to have a goal of $0.
159165
if self.goal != 0:
160166
self.output_participant_data()
161167
if self._first_run or self.number_of_donations > number_of_donations: # type ignore

eldonationtracker/utils/extralife_io.py

+19-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Holds all the file and internet input and output."""
22

3+
4+
import contextlib
35
import json
46
import logging
57
import os
@@ -12,8 +14,6 @@
1214
from donordrivepython.api.badge import Badge # type: ignore
1315
from donordrivepython.api.donation import Donation
1416
from donordrivepython.api.donor import Donor
15-
from rich import print
16-
from rich.logging import RichHandler
1717

1818
from eldonationtracker import file_logging
1919

@@ -90,19 +90,17 @@ def get_donations(donations_or_donors: list, api_url: str, is_donation=True, lar
9090
json_response = get_json(api_url, largest_first)
9191
if not json_response:
9292
el_io_log.error(f"[bold red]Couldn't access JSON endpoint at {api_url}.[/bold red]")
93-
return donations_or_donors
9493
else:
9594
if is_donation:
9695
donor_or_donation_list = [Donation(this_donation) for this_donation in json_response]
9796
else:
9897
donor_or_donation_list = [Donor(this_donor) for this_donor in json_response] # type: ignore
99-
if len(donations_or_donors) == 0: # if I didn't already have donations....
98+
if not donations_or_donors:
10099
return donor_or_donation_list
101-
else: # add in only the new donations
102-
for a_donation in reversed(donor_or_donation_list):
103-
if a_donation not in donations_or_donors:
104-
donations_or_donors.insert(0, a_donation)
105-
return donations_or_donors
100+
for a_donation in reversed(donor_or_donation_list):
101+
if a_donation not in donations_or_donors:
102+
donations_or_donors.insert(0, a_donation)
103+
return donations_or_donors
106104

107105

108106
def get_badges(api_url: str) -> list[Badge]:
@@ -350,7 +348,7 @@ def single_format(donor, message: bool, currency_symbol: str) -> str:
350348
return f"{donor.name} - {currency_symbol}{donor.amount:.2f}"
351349

352350

353-
def multiple_format(donors, message: bool, horizontal: bool,
351+
def multiple_format(donors: list[Donor], message: bool, horizontal: bool,
354352
currency_symbol: str, how_many: int) -> str:
355353
"""Format string for output to text file.
356354
@@ -399,13 +397,12 @@ def format_information_for_output(donation_list: list, currency_symbol: str, don
399397
:param team: If true, this is creating output for a team. Otherwise, for the participant.
400398
:returns: A dictionary with the output text formatted correctly.
401399
"""
402-
donation_formatted_output: dict = {}
403400
prefix = "Team_" if team else ''
404401
middle_text = "Donation" if donation else "Donor"
405-
donation_formatted_output[f'{prefix}Last{middle_text}NameAmnt'] = single_format(donation_list[0],
406-
False, currency_symbol)
407-
donation_formatted_output[f'{prefix}lastN{middle_text}NameAmts'] = \
408-
multiple_format(donation_list, False, False, currency_symbol, int(donors_to_display))
402+
donation_formatted_output: dict = {f'{prefix}Last{middle_text}NameAmnt': single_format(
403+
donation_list[0], False, currency_symbol
404+
), f'{prefix}lastN{middle_text}NameAmts': multiple_format(donation_list, False, False, currency_symbol,
405+
int(donors_to_display))}
409406
if donation:
410407
donation_formatted_output[f'{prefix}lastN{middle_text}NameAmtsMessage'] = \
411408
multiple_format(donation_list, True, False, currency_symbol, int(donors_to_display))
@@ -416,11 +413,9 @@ def format_information_for_output(donation_list: list, currency_symbol: str, don
416413
return donation_formatted_output
417414

418415

419-
def output_badge_data(badge_list: list[Badge], text_folder: str, team=False) -> None: # pragma: no cover
416+
def output_badge_data(badge_list: list[Badge], text_folder: str, team=False) -> None: # pragma: no cover
420417
"""Write out text and HTML files for badge data."""
421-
prefix = ''
422-
if team:
423-
prefix = "team_"
418+
prefix = "team_" if team else ''
424419
if badge_list:
425420
badge_text_output = {}
426421
badge_url_output = {}
@@ -435,9 +430,9 @@ def output_badge_data(badge_list: list[Badge], text_folder: str, team=False) ->
435430

436431

437432
def read_in_total_raised(text_folder: str) -> str:
438-
"""This is a temporary hack until I resolve Github issue #162"""
433+
"""This is a temporary hack until I resolve GitHub issue #162"""
439434
try:
440-
with open(f'{text_folder}/totalRaised.txt', 'r', encoding='utf8') as total_raised:
435+
with open(f'{text_folder}/totalRaised.txt', encoding='utf8') as total_raised:
441436
return total_raised.readline()
442437
except FileNotFoundError:
443438
el_io_log.info("[bold blue] totalRaised.txt doesn't exist. This is OK if this is your first run. [/bold blue]")
@@ -454,10 +449,8 @@ def write_text_files(dictionary: dict, text_folder: str):
454449
:param dictionary: The dictionary with items to output.
455450
:param text_folder: The directory to write the text files.
456451
"""
457-
try:
452+
with contextlib.suppress(FileExistsError):
458453
os.makedirs(text_folder)
459-
except FileExistsError:
460-
pass
461454
for filename, text in dictionary.items():
462455
with open(f'{text_folder}/{filename}.txt', 'w', encoding='utf8') as file:
463456
file.write(text)
@@ -470,10 +463,8 @@ def write_html_files(data: str, filename: str, text_folder: str):
470463
:param filename: The filename for the HTML file.
471464
:param text_folder: The directory to write the HTML files to.
472465
"""
473-
try:
466+
with contextlib.suppress(FileExistsError):
474467
os.mkdir(text_folder)
475-
except FileExistsError:
476-
pass
477-
html_to_write = "<HTML><body>" + data + "</body></HTML>"
468+
html_to_write = f"<HTML><body>{data}</body></HTML>"
478469
with open(f'{text_folder}/{filename}.html', 'w', encoding='utf8') as html_file:
479470
html_file.write(html_to_write)

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ coverage==6.4.1
1313
dill==0.3.5.1
1414
distlib==0.3.4
1515
docutils==0.18.1
16-
donordrivepython==1.4.5
16+
donordrivepython==1.6.0
1717
filelock==3.7.1
1818
identify==2.5.1
1919
idna==3.3
@@ -28,10 +28,10 @@ packaging==21.3
2828
platformdirs==2.5.2
2929
pluggy==1.0.0
3030
pprintpp==0.4.0
31-
pre-commit==2.19.0
31+
pre-commit==3.2.0
3232
py==1.11.0
3333
Pygments==2.12.0
34-
pyinstaller==5.1
34+
pyinstaller==5.9.0
3535
pyinstaller-hooks-contrib==2022.7
3636
pyparsing==3.0.9
3737
PyQt5==5.15.7

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ install_requires =
2626
semver == 3.0.0.dev3
2727
requests == 2.28.1
2828
rich == 12.4.4
29-
donordrivepython == 1.4.5
29+
donordrivepython == 1.5.0

0 commit comments

Comments
 (0)