Skip to content

Instantly share code, notes, and snippets.

@danared
Created February 12, 2016 16:47
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 danared/04a4df859f5c3cd6872b to your computer and use it in GitHub Desktop.
Save danared/04a4df859f5c3cd6872b to your computer and use it in GitHub Desktop.
def load_data(collection, n=100):
for i,d in load_data_file(n):
collection.insert( d )
def get_data(collection, query={}):
for d in collection.find(query):
yield d
# Load the entire contents of the collection in memory.
elements = []
for e in get_data(collection):
elements.append(e)
idx = random.randint(0, len(elements))
print "AND THE WINNER IS ..... " + elements[idx]['name']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment