Permalink
Browse files

Process multiple input dumps and provide sorting

  • Loading branch information...
1 parent 092bcd4 commit b37c4246a0d8013641f8f8d69506bb5fab809735 Andrew Nesbit committed Mar 5, 2012
Showing with 21 additions and 8 deletions.
  1. +21 −8 util/list_echoprint_dump.py
@@ -4,12 +4,25 @@
import json
if __name__ == '__main__':
- if len(sys.argv) != 2:
- sys.stderr.write("Usage: %s echoprint_json_dump\n", sys.argv[0])
+ prog_name = sys.argv[0]
+ if len(sys.argv) < 3:
+ sys.stderr.write("Usage: %s sort_key json_dump [json_dump ...]\n" % prog_name)
sys.exit(1)
- json_dump = sys.argv[1]
- j = json.load(open(json_dump))
- for c in j:
- m = c['metadata']
- sys.stdout.write(m['track_id'] + ' --- ' + m['artist'] + ' --- ' +
- m['release'] + ' --- ' + m['title'] + '\n')
+ sort_key = sys.argv[1]
+ if sort_key != 'artist' and sort_key != 'release' and sort_key != 'title':
+ sys.stderr.write('Error: %s: Unknown sort key `%s\'. Try `artist\', `release\' or `title\' instead\n' % (prog_name, sort_key))
+ sys.exit(1)
+ list_of_raw_dumps = sys.argv[2:]
+ summary_list = []
+ for d in list_of_raw_dumps:
+ j = json.load(open(d))
+ for c in j:
+ m = c['metadata']
+ summary_list.append({'track_id': m['track_id'],
+ 'artist': m['artist'],
+ 'release': m['release'],
+ 'title': m['title']})
+ summary_list.sort(key=lambda x: x[sort_key].lower())
+ for s in summary_list:
+ sys.stdout.write(s['track_id'] + ' --- ' + s['artist'] + ' --- ' +
+ s['release'] + ' --- ' + s['title'] + '\n')

0 comments on commit b37c424

Please sign in to comment.