CustomerOrganizer Project

Customer Organizer (found here) manages customer information in a logical way. The customer’s information is stored in a JSON file and an additional log file stores all the previous changes to that file. Like most of my projects, this one was born out of the need for such a program.

Reason for Project

After gaining a few customers for my side business, I noticed that I had important information that I needed to remember for each customer. I wrote most of this information down on pieces of paper and it didn’t take long before I had a small pile on my desk. I knew that if business kept up, I would soon have a problem and so I started to think of ways to organize everything. After running a few ideas into the ground, I decided it would be best to write a program to keep track of the information for me.

Process

I pulled out yet another piece of paper and sketched my plan for the program.  Before long, the paper was full of all the functions, methods, classes, and imports/exports that I would need to complete the project. I knew that this project would be easier than my previous projects as I was used to setting up these types of programs.

The next step in the project was to get the files sorted out. I knew that the .py files would be easy, but I also wanted each customer to have their own directory. The current project that’s on Github includes an example customer to test out the program. What’s not visible is that the program can create and move customer directories based on user input. This is where I encountered my only problem with the creation of the program.

Each customer (once created) will have a directory which contains two files: customer_name.json and customer_name_log.txt. I wanted to add a function that moved the customer’s directory into a directory called ‘old_customers’ if that customer was no longer an active customer. So, I imported the sys module in hopes that I could move these files. Long story short, I hit a brick wall. An error kept occurring as the files couldn’t exist in two states: moved and unmoved. I then took to Google to see if an answer could be found; there was one! The module shutil did exactly what I wanted to do and so the problem was solved.

Code Snippets

The only piece of code that’s interesting besides the directory-moving function is the code for the log files. Take a look at the function that updates the customer’s log files (written in Python 3):

def update_log(name, update):
    """Writes updates to customers log .txt file.

    Args:
         name (str): Customers name; used for reading from and writing to their .txt log file.
         update (str): Update to to written to customers .txt log file.

    """
    f_txt = open("customer_files/{0}/{0}_log.txt".format(name), "a")
    now = datetime.datetime.now()
    date_format = "{Y}/{M}/{D} - ".format(Y=now.year, M=now.month, D=now.day)
    f_txt.write(date_format + update + "\n")
    f_txt.close()

This code seems simple enough, but there is plenty to discuss about it. First, this function is called in every function that changes the attributes of the customer_name.json file. Second, this function writes the date on which said change occurred with what the change was in sentence form (each line being one change). Third, the function only writes to the customer_name_log.txt file if they are an active customer (if the customer’s directory is in customer_files. Finally, the printout to the user letting them know that the change was successful is passed into this function (changed to sentence form) for it to be written to the customer_name_log.txt file.

Overall

Customer Organizer was a good project to code and is actually useful! I now use it to hold my side businesses customer’s information and I know that the information is logged, saved, and backed up. I might code a GUI for the program, but I am quite happy with the program as it is.

If you have any comments or suggestions, feel free to let me know below. Want to try out the program for yourself? The program is available here (just fork the repository and clone it to your computer).