Skip to content

Instantly share code, notes, and snippets.

@ekohl
Created March 17, 2010 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekohl/335825 to your computer and use it in GitHub Desktop.
Save ekohl/335825 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import csv
import sys
import random
# For each argument to the program
for arg in sys.argv[1:]:
# Store all the data
rows = list(csv.DictReader(open(arg)))
trackers = list(set(row['Tracker'] for row in rows))
# Pick a random tracker
tracker = trackers[random.randint(0, len(trackers)-1)]
# Print the data
for row in ( row for row in rows if row['Tracker'] == tracker ):
# The following 2 lines are equal
#print "[%s] %s: %s" % (row['Tracker'], row['Author'], row['Subject'])
print "[%(Tracker)s] %(Author)s: %(Subject)s" % row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment