Skip to content

Instantly share code, notes, and snippets.

Created March 2, 2011 01:49
What would you like to do?
dirty csv test data gen
#! /usr/bin/env python
from optparse import OptionParser
import sys, csv, os.path, random
def main():
usage = "usage: %prog [options] arg"
parser = OptionParser(usage)
parser.add_option("-t", "--template", dest="filename",
help="use FILENAME as CSV template")
parser.add_option("-d", "--date", dest="date",
help="use DATE as date field")
# any more preamble goes here
(options, args) = parser.parse_args()
if os.path.isfile(options.filename):
reader = csv.reader(open(options.filename, "rb"))
writer = csv.writer(sys.stdout)
# first write the headers out
writer.writerow( )
# now print the rest of the file:
for line in reader:
line[0] = # set the date
# line[1] is the unchanged page url
line[2] = random.randint(200,5000)
line[3] = random.randint(150,4000)
line[4] = random.uniform(30,1000)
line[5] = random.random()
line[6] = random.random()
print "Could not read file %s" % options.filename
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment