DV Wright Music

DistroKid, play totals python scripting (not as) fun…

So, yesterday I made a post playing with ruby. Today I decided to do the same thing with Python. It produces the same results but probably in a much more round about manner, I’m sure this could be greatly improved.

from collections import defaultdict
import operator

AutoV = lambda: defaultdict(AutoV)

f = open('/home/dwright/downloads/DistroKid_.tsv', 'r').readlines()

count = AutoV()

for i in f:
  song = i.split('\t')[4]
  plays = i.split('\t')[5]
  if song == 'Title':
    continue
  if not count[song]:
    count[song] = 0
  count[song] += int(plays)

counts = sorted(count.items(), key=operator.itemgetter(1), reverse=True)

for k,v in counts:
  print k,v

Blue Conga 88
Am Pm 83
Moms and Daughters 61
Lounging Chair 60
Blue Miles 59
Sandy Beach Bossa 54
These Times 52
Missed What You Meant 47
Pt 45
Sleepy Time 45
Cloth Hat Bossa 44
Mood Ring 38
Well If That’s What You Want, Try to Do That 37
Sunset Sands 35
Soccer Ball On the Roof 31
Hugs 2
Reach 2
Firmware Upgrade 2
Right Turn At Albuquerque 2
SleepThree 1
Pop Talk 1
Stay-Cation 1
Tymer 1
Blue Beach Boardwalk 1

Leave a Reply