Categories We Write About

Our Visitor

0 2 6 3 1 0
Users Today : 1182
Users This Month : 26309
Users This Year : 26309
Total views : 28311

Track donation records with Python

Tracking donation records with Python can be effectively managed by designing a simple program or script that handles donations data, stores it, and allows querying or reporting. Below is a detailed approach and an example implementation to track donation records.


Key Features to Include in Donation Tracking

  • Add new donations with donor name, amount, date, and possibly notes.

  • Store donation records in a persistent way (e.g., CSV file, JSON, or a database).

  • View donation history filtered by donor or date range.

  • Summarize donations (total amount, average donation, number of donations).

  • Search donors or donation records.

  • Export data if needed.


Example Implementation: Donation Tracker Using Python and CSV

python
import csv from datetime import datetime FILE_NAME = 'donations.csv' def initialize_file(): try: with open(FILE_NAME, 'x', newline='') as file: writer = csv.writer(file) writer.writerow(['Donor Name', 'Amount', 'Date', 'Notes']) except FileExistsError: pass # File already exists def add_donation(donor_name, amount, date=None, notes=''): if date is None: date = datetime.now().strftime('%Y-%m-%d') with open(FILE_NAME, 'a', newline='') as file: writer = csv.writer(file) writer.writerow([donor_name, amount, date, notes]) def read_donations(): donations = [] try: with open(FILE_NAME, 'r', newline='') as file: reader = csv.DictReader(file) for row in reader: row['Amount'] = float(row['Amount']) donations.append(row) except FileNotFoundError: print("Donation file not found. Initializing new file.") initialize_file() return donations def get_total_donations(): donations = read_donations() total = sum(d['Amount'] for d in donations) return total def get_donations_by_donor(donor_name): donations = read_donations() return [d for d in donations if d['Donor Name'].lower() == donor_name.lower()] def print_donations(donations): for d in donations: print(f"{d['Date']} - {d['Donor Name']} donated ${d['Amount']:.2f} - Notes: {d['Notes']}") def main(): initialize_file() while True: print("nDonation Tracker Menu:") print("1. Add Donation") print("2. View All Donations") print("3. View Donations by Donor") print("4. View Total Donations") print("5. Exit") choice = input("Enter your choice: ") if choice == '1': donor = input("Enter donor name: ") amount = float(input("Enter donation amount: ")) date = input("Enter donation date (YYYY-MM-DD) or leave blank for today: ") notes = input("Enter notes (optional): ") if not date: date = None add_donation(donor, amount, date, notes) print("Donation added successfully.") elif choice == '2': donations = read_donations() print_donations(donations) elif choice == '3': donor = input("Enter donor name to search: ") donations = get_donations_by_donor(donor) if donations: print_donations(donations) else: print(f"No donations found for {donor}.") elif choice == '4': total = get_total_donations() print(f"Total donations received: ${total:.2f}") elif choice == '5': print("Exiting Donation Tracker.") break else: print("Invalid choice. Please enter a number from 1 to 5.") if __name__ == "__main__": main()

How This Works:

  • The program creates or uses a CSV file named donations.csv to store donation records.

  • Each donation includes donor name, amount, date, and optional notes.

  • The menu-driven interface allows adding donations, viewing all donations, filtering donations by donor, and viewing total donation amounts.

  • Donations are stored persistently and can be accessed or updated across runs.


Possible Extensions

  • Use a database like SQLite for better data management.

  • Add data validation and error handling.

  • Generate donation reports (monthly, yearly).

  • Add donor contact info and manage donor profiles.

  • Create a web interface or use frameworks like Flask/Django for online tracking.

This simple Python donation tracker can be easily expanded and customized to fit specific requirements for nonprofits, fundraising events, or individual record-keeping.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About