extralife_io¶
Holds all the file and internet input and output.
-
class
eldonationtracker.utils.extralife_io.
ParticipantConf
¶ Bases:
object
Holds Participant Configuration info.
- Parameters
cls.participant_conf_version – version of participant.conf
cls.version_mismatch – Initialized to False.If true, the user has a different version of the participant.conf.
cls.fields – A dictionary initialed to None for all fields.
self.xdg – By using the PedanticPackage, the directory will be created if it doesn’t already exist.
self.participantconf – holds a dictionary of the user’s config file.
-
fields
: dict = {'currency_symbol': None, 'donation_sound': None, 'donors_to_display': None, 'extralife_id': None, 'font_bold': None, 'font_color': None, 'font_family': None, 'font_italic': None, 'font_size': None, 'team_id': None, 'text_folder': None, 'tracker_background_color': None, 'tracker_image': None}¶
-
get_cli_values
() → Tuple[Any, Any, Any, Any, Any]¶ Return data required for a CLI-only run.
- Returns
A tuple of strings with config values needed if only running on the commandline.
-
get_font_info
()¶ Return values needed to change the font for the tracker.
- Returns
A tuple of strings and a list for the color.
-
get_github_config
()¶
-
get_gui_values
() → Tuple[Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any]¶ Return values needed for the GUI.
- Returns
A tuple of strings with config values needed if only running the GUI. The two background colors are lists.
-
get_if_in_team
() → bool¶ Return True if participant is in a team.
- Returns
True if the participant is in a team.
-
get_text_folder_only
() → str¶ Return text folder data.
- Returns
A string with the text folder location.
-
get_tracker_assets
(asset: str)¶
-
get_tracker_background_color
()¶ Return value needed to change the tracker background color
- Returns
A list representing the RGB value for the background
-
get_tracker_image
() → str¶ Return the tracker image location on disk.
- Returns
Location of tracker image on disk.
-
get_tracker_sound
() → str¶ Return the donation sound image location on disk.
- Returns
location of the donation sound on disk.
-
get_version
()¶ Return version.
-
get_version_mismatch
() → bool¶ Return bool of whether there is a version mismatch.
- Returns
True if the version the user is running is not the same as what this program has as its version.
-
load_json
() → dict¶ Load in the config file.
Checks in a variety of locations for the participant.conf file. First, it checks in the persistent settings location (XDG_CONFIG_HOME) . Then it checks the current directory and one level up. Otherwise it raises an exception and the program stops.
- Returns
A dictionary representing the JSON config file.
- Raises
FileNotFoundError
-
participant_conf_version
: str = '2.0'¶
-
reload_json
()¶ Reload JSON and update the fields.
-
update_fields
()¶ Update fields variable with data from JSON.
-
version_mismatch
: bool = False¶
-
write_config
(config: dict, default: bool)¶ Write config to file.
Only called from GUI. Commandline user is expected to edit participant.conf manually. Afterward it triggers self.reloadJSON to have the program run with the updated config.
- Parameters
config – A dictionary holding the config values.
default – If True, will save the file in the current directory.
-
eldonationtracker.utils.extralife_io.
format_information_for_output
(donation_list: list, currency_symbol: str, donors_to_display: str, team: bool, donation=True) → dict¶ Format the donation attributes for the output files.
- Parameters
donation –
donation_list (list) – A list of donors or donations to format for output.
currency_symbol – The currency symbol for the output.
donors_to_display – How many donors or donations to display
team – If true, this is creating output for a team. Otherwise, for the participant.
- Returns
A dictionary with the output text formatted correctly.
-
eldonationtracker.utils.extralife_io.
get_donations
(donations_or_donors: list, api_url: str, is_donation=True, largest_first=False) → list¶ Get the donations from the JSON and create the donation objects.
If the API can’t be reached, the same list is returned. Only new donations are added to the list at the end.
- Parameters
is_donation – True if we are getting data for donations. False if we are getting data for donors.
largest_first – True if we want to sort by largest. False if sort by latest donors or donations.
donations_or_donors – A list consisting of donation.Donation or donor.Donor objects.
api_url – The URL to go to for donations.
- Returns
A list of donation.Donation objects.
-
eldonationtracker.utils.extralife_io.
get_json
(url: str, order_by_donations: bool = False, order_by_amount: bool = False) → dict¶ Grab JSON from server.
Connects to server and grabs JSON data from the specified URL. The API server should return JSON with the donation data.
- Parameters
url – API URL for the specific json API point.
order_by_donations – If true, the url param has data appended that will cause the API to return the data in descending order of the sum of donations.
order_by_amount – If true, the url param has data appended that will cause the API to return the data in descending order of the sum of amounts.
- Returns
JSON as dictionary with API data.
- Raises
HTTPError, URLError
-
eldonationtracker.utils.extralife_io.
multiple_format
(donors, message: bool, horizontal: bool, currency_symbol: str, how_many: int) → str¶ Format string for output to text file.
This function is for when there is are multiple donors or donations. For example, for the text file holding the Top 5 donors.
- Parameters
donors – An iterable of Donors or Donations class objects.
message – If True, the message (if any) from the donor object :param horizontal: If True, format the message horizontally. Else vertically.
currency_symbol – The currency symbol to append to the return string.
how_many – A number for how many donors/donations to append to the string.
- Returns
A string containing the inputs formatted.
Horizontal example:
John Doe - $100.00 - Thanks for raising money for the kids. | Jane Doe - $25.00 - Hurray!
Vertical example:
John Doe - $200.00 - a message
Jane Doe - $75.00 - another message
-
eldonationtracker.utils.extralife_io.
single_format
(donor, message: bool, currency_symbol: str) → str¶ Format string for output to text file.
This function is for when there is only one donor or donation. For example, for the text file holding the most recent donation.
- Parameters
donor – Donor or Donation class object.
message – If True, the message (if any) from the donor object :param currency_symbol: The currency symbol to append to the return string.
- Returns
A string containing the inputs formatted. For example:
John Doe - $100.00 - Thanks for raising money for the kids.
-
eldonationtracker.utils.extralife_io.
validate_url
(url: str)¶
-
eldonationtracker.utils.extralife_io.
write_html_files
(data: str, filename: str, text_folder: str)¶ Write data to an HTML file.
- Parameters
data – The data to write to an HTML file.
filename – The filename for the HTML file.
text_folder – The directory to write the HTML files to.
-
eldonationtracker.utils.extralife_io.
write_text_files
(dictionary: dict, text_folder: str)¶ Write info to text files.
The dictionary key will become the filename and the values will be the content of the files.
- Parameters
dictionary – The dictionary with items to output.
text_folder – The directory to write the text files.