extralife_io

Holds all the file and internet input and output.

class eldonationtracker.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 = {'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[str, int]

Return data required for a CLI-only run.

Returns

A tuple of strings with config values needed if only running on the commandline.

get_GUI_values() → Tuple[str, int]

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_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_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.0

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 = '2.0'
reload_JSON()

Reload JSON and update the fields.

update_fields()

Update fields variable with data from JSON.

version_mismatch = 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.extralife_IO.get_JSON(url: str, order_by_donations: 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 has text appended that will cause the API to return the data in descending order of the sum of donations.

Returns

JSON as dictionary with API data.

Raises

HTTPError, URLError

eldonationtracker.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.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.extralife_IO.validate_url(url: str)
eldonationtracker.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.