• Version: this should be left alone. It’s to know if a persistent config needs updating
• extralife_id: this should be your extralife id, the end of your campaign URL
• text_folder: this is where the text files generated by the program will be placed
• currency_symbol: the prefix for your money
• team_id: if you’re on a team, grab from team page URL. If not, put null without quotation marks
• tracker_image: if you’re using the GUI, what you want to appear when you get a donation
• donation_sound: if you’re using GUI, what you want to hear when there’s a donation
• donors_to_display: controls how many donors/donations appear in files that have more than one
The values corresponding to the tracker (everything after donors_to_display) is best configured in the GUI to ensure you’re getting values that make sense on your system.
CHAPTER
FOUR
CALL_ABOUT
Contains programming logic for the about window in the GUI.
eldonationtracker.call_about.main()
15
CHAPTER
FIVE
CALL_SETTINGS
Contains the programming logic for the settings window in the GUI.
eldonationtracker.call_settings.main(participant_conf ) Launch the window.
17
CHAPTER
SIX
CALL_TRACKER
A window that displays the last donation. Useful during streaming.
eldonationtracker.call_tracker.main(participant_conf ) Launch the window.
19
CHAPTER
SEVEN
DONATION
A class to hold the Donation attributes and methods.
class eldonationtracker.donation.Donation(name, message, amount, donor_id, avatar_url, donation_date, donation_id)
Bases: object Donation Attributes.
Class exists to provide attributes for a donation based on what comes in from the JSON so that it doesn’t have to be traversed each time a donor action needs to be taken.
Parameters
• name (str) – the name of the donor for this donation. If the donor wished to stay anony-mous, the variable is set to/ “Anonymous”
• message (str) – the message associated with the donation.
• amount (int) – the amount of the donation. If they blocked it from showing it is set to 0.
get_amount()
Format the donation attributes for the output files. dict
eldonationtracker.donation.get_donations(donations: list, donation_url: str) → 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
• donations – A list consisting of donor.Donation objects.
• donation_url – The URL to go to for donations.
Returns A list of donor.Donation objects.
21
CHAPTER
EIGHT
DONOR
A donor.
class eldonationtracker.donor.Donor(json) Bases: object
Donor Attributes.
Class exists to provide attributes for a donor based on what comes in from the JSON so that it doesn’t have to be traversed each time a donor action needs to be taken.
Parameters
• json (json) – JSON attributes from the API
• self.name – donor’s name if provided, else Anonymous
• self.donor_id – the ID assigned by the API (currently not used)
• self.image_url – the URL for the donor’s avatar (currently not used)
• self.amount – the sum of all donations the donor has made this campaign
• self.number_of_donations – the number of donations the donor has made this cam-paign
json_to_attributes(json)
Convert API JSON values to Donor attributes.
May be overwritten by child classes.
Parameters json (json) – JSON attributes from the API
23
CHAPTER
NINE
PARTICIPANT
Grabs Participant JSON data and outputs to files.
class eldonationtracker.participant.Participant(config) Bases: object
Owns all the attributes under the participant API.
Also owns the results of any calculated data.
Donor Drive API api info athttps://github.com/DonorDrive/PublicAPI Parameters
• self.extralife_id (int) – the participant’s extra life ID
• self.text_folder (str) – where the output text files will be written on disk
• self.currency_symbol (str) – for the output text files
• self.donors_to_display (int) – for text files that display multiple donors (or do-nations), the number of them that should be written to the text file.
• self.participant_url (str) – API info for participant
• self.donation_url (str) – donation API info
• self.participant_donor_url (str) – API info for donors. Useful for calculating top donor.
• self.total_raised (int) – total amount raised by the participant
• self.number_of_donations (int) – the number of donations received by the par-ticipant
• self.average_donation (int) – The average amount of donations for this partici-pant
• self.goal (int) – The goal for the amount of the money the participant wishes to raise
• self.participant_formatted_output (dict) – a dictionary holding data about the participant
• self.my_team (cls: eldonationtracker.team) – An instantiation of a team class for the participant’s team.
• self.donation_list (list) – a list of Donation class objects made of donations to this participant
• self.donation_formatted_output (dict) – a dictionary holding values for txt output
25
output_donation_data()→ None Write out text files for donation data.
If there have been donations, format the data (eg horizontally, vertically, etc) and output to text files. If there have not yet been donations, write default data to the files.
output_donor_data()→ None Write out text files for donor data.
If there have been donations, format the data (eg horizontally, vertically, etc) and output to text files. If there have not yet been donations, write default data to the files.
output_participant_data()→ None
Format participant data and write to text files for use by OBS or XSplit.
A public method to do the above. Also called from the main loop.
run()→ None
Run to get participant, donation, donor, and team data and output to text files.
set_config_values()→ None
Set participant values, create URLs, and create Team.
update_donation_data()→ None Update donation data.
As of 5.0 it just updates the list of donations. There may be more donation-related updating in future versions.
update_donor_data()→ None Update donor data.
As of 5.0 it only grabs the top donor. There may be more donor-related updates in the future.
update_participant_attributes()→ None Update participant attributes.
A public method that will update the Participant object with data from self.participant_url.
Also called from the main loop.
write_text_files(dictionary: dict)→ None Write OBS/XSplit display info to text files.
It uses the helper function extralife_IO.write_text_files to handle the task.
Parameters dictionary (dict) – Dictionary containing values to write to text files . The key will become the filename. The value will be written to the file.
CHAPTER
TEN
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 al-ready 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 back-ground 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.
27
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.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
eldonationtracker, Release 5.2.1
• 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.
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.
29
• text_folder – The directory to write the text files.
CHAPTER
ELEVEN
GUI
The main GUI window.
eldonationtracker.gui.main()
31
CHAPTER
TWELVE
IPC
Writes to an IPC value to allow different modules to pass information.
This is used to allow the tracker to know that new data needs to be read in because a new donation has occurred.
eldonationtracker.ipc.write_ipc(folder: str, value: str) Write to the IPC file.
This is used to let the call_tracker module know that a new donation has been made.
Parameters
• folder – The location of trackerIPC.txt
• value – The value to write to the file.
Raises IOError
33
CHAPTER
THIRTEEN
TEAM
Contains classes pertaining to teams.
class eldonationtracker.team.Team(team_id: str, output_folder: str, currency_symbol: str, donors_to_display: str)
Bases: object Hold Team API Data.
Parameters
• self.team_id – The team’s ID in the API
• self.team_url – URL to the team JSON API
• self.team_participant_url – URL to the JSON api for participants in the team.
• self.team_donation_url – URL to the JSON api for donations to the team
• self.output_folder – The folder for the output text files
• currency_symbol – for formatting text
• self.team_info – a dictionary to values for output to text files
• self.participant_calculation_dict – dictionary holding output for txt files
• self.top_5_participant_list – a list of the top 5 team participants by amount donated.
• self.team_json – A dictionary to hold JSON info from the API
• self.team_goal – the fundraising goal of the team.
• self.team_captain – The name of the team captain.
• self.total_raised – The total amount raised by the team.
• self.num_donations – The total amount of donations to the team.
• self.top_5_participant_list – The top 5 participants in the team
• self.participant_list – a list of the most recent participants donation_run()→ None
Get and calculate donation information.
participant_run()→ None
Get and calculate team participant info.
team_api_info()→ None Get team info from API.
35
team_run()→ None
A public method to update and output team and team participant info.
write_text_files(dictionary: dict)→ None Write info to text files.
Parameters dictionary – The dictionary containing the values to write out to text files.
CHAPTER
FOURTEEN
TEAM_PARTICIPANT
class eldonationtracker.team_participant.TeamParticipant(json) Bases:eldonationtracker.donor.Donor
Participant Attributes.
Inherits from the donor class, but over-rides the json_to_attributes function.
API variables:
Parameters
• self.name – participant’s name or Anonymous
• self.amount – the sum of all donations by this participant
• self.number_of_donations – number of all donations by this participant
• self.image_url – the url of the participant’s avatar image (not used) json_to_attributes(json)
Convert JSON to Team Participant attributes.
Parameters json – JSON attributes from API
37
CHAPTER
FIFTEEN
UPDATE_AVAILABLE
Return true if there is an update available.
An update is available if the version on PyPi is higher than the version the user has on their machine.
eldonationtracker.utils.update_available.get_pypi_version(url: str)→ str Use PyPi JSON API to get latest version.
Returns A string with the version number.
eldonationtracker.utils.update_available.main()→ bool Get the latest version on PyPi and compare to current version.
Made the decision to return false if the URL couldn’t be reached rather than make the user look for an update that might not be there.
Returns True if there’s an update available. False if up to date.
eldonationtracker.utils.update_available.update_available(pypi_version: str, cur-rent_version: str) → Use semver module to calculate whether there is a newer version on PyPi. bool
Returns True if the PyPi version is higher than the version being run. Returns false if the version being compared to PyPi is equal or greater than the PyPi version.
39
CHAPTER
SIXTEEN
INDICES AND TABLES
• genindex
• modindex
• search
41
PYTHON MODULE INDEX
e
eldonationtracker.call_about,15 eldonationtracker.call_settings,17 eldonationtracker.call_tracker,19 eldonationtracker.donation,21 eldonationtracker.donor,23
eldonationtracker.extralife_io,27 eldonationtracker.gui,31
eldonationtracker.ipc,33
eldonationtracker.participant,25 eldonationtracker.team,35
eldonationtracker.team_participant,37 eldonationtracker.utils.update_available,
39
43
INDEX
D
Donation(class in eldonationtracker.donation),21 donation_run() (eldonationtracker.team.Team
method),35
Donor(class in eldonationtracker.donor),23
E
J
main()(in module eldonationtracker.call_about),15 main()(in module eldonationtracker.call_settings),17 main()(in module eldonationtracker.call_tracker),19 main()(in module eldonationtracker.gui),31
main() (in module
Team(class in eldonationtracker.team),35
team_api_info() (eldonationtracker.team.Team
eldonationtracker, Release 5.2.1
write_ipc()(in module eldonationtracker.ipc),33
write_text_files()
(eldonation-tracker.participant.Participant method), 26
write_text_files()(eldonationtracker.team.Team method),36
write_text_files() (in module eldonation-tracker.extralife_io),29
Index 47