Skip to content

Instantly share code, notes, and snippets.

@kgorman
Created September 22, 2010 01:28
Show Gist options
  • Save kgorman/590951 to your computer and use it in GitHub Desktop.
Save kgorman/590951 to your computer and use it in GitHub Desktop.
#!/home/kgorman/python/bin/python
# script to make sample data for testing
#
import datetime
import pymongo
import time
import sys
import random
import settings
from pymongo import ASCENDING, DESCENDING
from pymongo import Connection
connection = Connection(["al06:27017","al07:27017"])
db = connection.test
images=db.images
alltags=['dogs','beach','vacation','baby','house','fun','kids','xmas','halloween','food','cars','county fair']
# create a basic images object
themax=0
try:
for i in images.find().limit(1).sort("owner",-1):
themax=i['owner']
except:
themax=0
end=themax+6133810
#end=themax+10
start=themax+1
print "starting:"+str(start)
print "ending:"+str(end)
for i in range(start,end):
owner=i
albumname="Album_"+str(i)
foldername="Folder_"+str(i)
path=str(i)+"/"+foldername+"/"+albumname
for ii in range(1,random.randint(10,100)):
mytags=random.sample(alltags,4)
imagename=str(owner)+"_image_"+str(ii)
image={"_id":imagename,"owner":owner,"path":path,"name":imagename,"tags":mytags,"LocationSpec":imagename,
"creation_date":datetime.datetime.now(),"updated_date":datetime.datetime.now()}
images.insert(image,safe=True,w=2)
print (i)
print( "done inserting, creating indexes" )
images.ensure_index( "name" )
images.ensure_index( "owner" )
print( "done creating indexes" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment