Some neighborhood shenanigans led a group of home owners to start a GoFundMe page to raise money to file a lawsuit against the city. The backstory isn’t important. I was curious to know who would support this bad behavior, and I wanted to practice my python.

I was able to cut-and-paste information about the people who made donations to the GoFundMe effort. That information went into a text file. Each line had a different bit of information: initials of a donor, how much they donated, their name (or “Anonymous”), and some information about when they made their donation. It’s not easy to aggregate information presented this way. Wouldn’t it be nice to have it in a spreadsheet where I could sort and pivot and all that?

So that was my project: taking the scraped text and messaging the information into CSV format that can be imported into a spreadsheet.

Sounds easy. Looksing back, it was easy. But it took time. I felt I was learning python for the first time. Again. The exercise taught me something about functions, lists, operators, and running python on my home computer. It also made me wrestle with types (and changing them when it suited me).

There’s not much to say about the process, and there are no creative steps that would much interest anybody else. This is the result of much pseudocoding, discarding of ideas, and trying things, making small tweaks until something works the way I hoped it would. Engineering, I guess.

Here’s the code:

    import numpy as np
    import csv
    # function takes a list and outputs the locations in the list that equal ''
    # in:  list
    # out:  list of location indices of '' elements
    def indices(listname):
        indices = [i for i,x in enumerate(listname) if x=='']
        return np.array(indices)
    # function that takes list of indices and give the lengths of the subsequences of strings between the '\n'
    # in: list of indices, original list of interest
    # out: list of lengths
    def lengths(indices,list):
        lengths[1:M-1]=np.array(indices[1:M-1]) - np.array(indices[0:M-2])-1
        return lengths
    # function that takes an index, a list of indices, and lengths of subsequences and returns a row of the CSV file I aim to creat
    # in: a row number, a list of indices, the lengths of the rows
    # out: indeces for the elements of the row in question
    def rowi_indices(i,indices,lengths):
        if i==0:
            list = [0]
            while j < lengths[0]:
            list = [indices[i]+1]
            while j < lengths[i]:
        return list   
    # function that takes an index, a list of data, and location indices of the line breaks and gives back a row of the CSV file
    # in: a row number, a list of data, a list of indices
    # out: the row in question
    def rowi(i, list, indices):
        row = [data[i] for i in good_indices]
        return row
    # -------------------------
    # this is the file that has the scraped data
    # read the file into python
    # strip the carriage retuns from the data; rows will be separated by "blanks" where there were only carriage returns, before
    data = [x.strip('\n') for x in data] 
    # locations of the row breaks
    indices = indices(data)
    # computing all the rows of the CSV file
    while j < len(indices):
    # Open File
    resultFile = open("output.csv",'w')
    # Write data to file
    for r in rows:
        # need to strip the square brackets from the start and end of each row, too
        resultFile.write(str(r).strip('][') + "\n")
    # TADAH!