anonscrobbles.py 706 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. import random
  3. s = open("scrobbledump.sql", "r")
  4. o = open("scrobbles.anonymous.sql", "w")
  5. datasection = False
  6. usermap = {}
  7. #track, artist, "time", mbid, album, source, rating, length, stid, userid, track_tsv, artist_tsv
  8. for line in s.readlines():
  9. if line.rstrip() == "\.":
  10. datasection = False
  11. if datasection:
  12. data = line.split("\t")
  13. uid = data[9]
  14. if uid in usermap:
  15. data[9] = str(usermap[uid])
  16. else:
  17. newid = random.randint(0, 1000000)
  18. while newid in usermap:
  19. newid = random.randint(0, 1000000)
  20. usermap[uid] = newid
  21. data[9] = str(newid)
  22. o.write("\t".join(data))
  23. else:
  24. o.write(line)
  25. if line[:4] == "COPY":
  26. datasection = True
  27. s.close()
  28. o.close()