I've been wanting to get more involved in self tracking, but never had enough programming knowledge to make it happen. Recently, I've put all of my writing in Dropbox so that it would be easier to access from multiple devices. Combining that with some basic knowledge in Python means that I can begin tracking the number of words I'm producing, no matter what file it is in.

The requirements for my files is that I can access from any device and write/preview in Markdown. I'm using Editorially on iOS, which can save to a specific Dropbox folder. On Windows I use MarkdownPad2, and work in the same folder. Any application that can modify/save to a single Dropbox directory would work, though.

The Python part is pretty simple and involves looping through all files in a directory and getting some basic statistics and appending those to a csv file.

# track_words_in_directory## Run at startup, and add to csv file, the statistics for a given directory##importosimportcsvimportdatetimeBASE_DIR=r'C:\......\Dropbox\Apps\Editorial'OUTPUT_FILE=r'C:\.......\Dropbox\Programming\word_counts.csv'file_count=0file_lines=0file_words=0file_chars=0fordirname,dirnames,filenamesinos.walk(BASE_DIR):forfilenameinfilenames:my_file=os.path.join(dirname,filename)file_count+=1withopen(my_file,'r')asf:forlineinf:file_lines+=1words=line.split()file_words+=len(words)file_chars+=len(line)print'files:%s'%file_countprint'lines:%s'%file_linesprint'words:%s'%file_wordsprint'chars:%s'%file_charscurrent_date=datetime.datetime.now().strftime("%Y-%m-%d %H:%M")output_line=(current_date,file_count,file_lines,file_words,file_chars)printoutput_lineout_file=open('tracking.csv','ab')#wbfirst,aforappendwriter=csv.writer(out_file)#writer.writerow(('date', 'file_count', 'file_lines', 'file_words', 'file_char'))writer.writerow(output_line)out_file.close()

The one thing I don't know how to do yet, is setup the script to run every so often.

Going further, it would be interesting to add some notifications more frequently while I was writing or to look for other measurable things to compare this with.