-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Here are my suggestions:
Procedure:
- Get donor info from csv file
- Create a database connection
- Compare it with database(Table Individuals) if donor exists using last
name, first name, and then street address(Check with last name first)
3.a. If user does not exist :
3.a.1. Create an insert statement using donor info from csv file for table "Individuals"
from CSV: Donor First Name, Donor Last Name, Donor Address 1, Donor City, Donor Province, Donor Postal/Zip Code
3.a.2. Get the ID# generated for newly created user
3.b. If user has multiple records
3.b.1. Selection method
3.b.1.a. Do a random selection
3.b.1.b. Use the first one (easiest)
3.b.1.c. Find for the record with the most transactions (most complex)
3.b.2. Get the ID# of selected user
3.c. If user has already a record, get the ID# - Generate an insert statement for table "Money_Brought_In" and execute it(use ID#)
- Close the csv file and database connector
Functions:
def get_donor_info(csvfile):
-get donor's information and store in a list or dictionary
-input: csvfile - csv file name
-output: or of donor's information
def get_sql_connector(host, user, password, dbname):
-connect to database and output the SQL object
-input: host - host name
user - username
password - password
dbname - database name
-output: MySQL object
def exec_sql_statement(sqlobject,statement ):
-execute the input sql statement
-input: sqlobject - SQL object to use
statement - to execute
-output: if error occurs
def generate_insert_individual(donor_info):
-input: donor_info - or of donor information from csv file
-output: SQL statement
def generate_insert_moneybroughtin(donor_info)
-input: donor_info - or of donor information from csv file
-output: SQL statement
References:
MySQL module on Python -
http://www.tutorialspoint.com/python/python_database_access.htm
CSV module on Python - https://docs.python.org/3/library/csv.html
1)open the file
2)read the input of the last name of the customer
a)if the customer is in the file
-read the credit
b)else if customer is not in the file
-make a new file for him/her
3)read the lines, divide the values into their respectable attributes
4)each line is one tuple
5)continue until there’s no more.
-
Open and read the csv file.
-
Compare the donor's last name, first name, and address (street number, city, province, postal code) from the csv file with available donors' information in the "Individuals" table.
2.1 If the person of checking is already created in the database, get his/her ID from the database.
2.1.1 Insert the donor's information to the "Individuals" table.
2.1.2 Insert the donor's payment information to the "Money_Brought_In" table.2.2 If the person of checking is NOT in the database yet, create a new entry in the "Individuals" table.
2.2.1 Check if the donation is done by an individual or organization.
2.2.2 Insert the donor's information to the "Individuals" table.
2.2.3 Insert the donor's payment information to the "Money_Brought_In" table. (Note: The "cash" field of "Money_Brought_in" table is always set to 0 and data from "Payment Method" field of the csv file is inserted to "For" field of "Money_Brought_in" table) -
Go back to step 2 until finishing all the entries of the csv file.