Ejemplo n.º 1
0
    def setUp(self):
        self.sample = """
        One two three four five six. Seven eight nine ten eleven twelve.

        Thirteen fourteen fifteen sixteen. Seventeen eighteen nineteen twenty.
        """
        self.dictionary = "a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh iiiiiiiii jjjjjjjjjj kkkkkkkkkkk llllllllllll".split()
        self.generator = lipsum.Generator(self.sample, self.dictionary)
Ejemplo n.º 2
0
    def design(self, profile):
        if profile.has_key("family_name"):
            family_name = profile["family_name"]

            random.seed(family_name)
            lipsum_generator = lipsum.Generator()
            lipsum_generator.sentence_mean = 3
            lipsum_generator.sentence_sigma = 1

            return lipsum_generator.generate_sentence()[:-1]
        else:
            return None
Ejemplo n.º 3
0
import io
import avro.schema
import avro.io
import lipsum
import random

from kafka.client import KafkaClient
from kafka.producer import SimpleProducer, KeyedProducer

g = lipsum.Generator()
kafka = KafkaClient("localhost:9092")
producer = SimpleProducer(kafka)

# Path to user.avsc avro schema
schema_path="/Your/schema/path/user.avsc"

# Kafka topic
topic = "test"

schema = avro.schema.parse(open(schema_path).read())


for i in xrange(2000):

	writer = avro.io.DatumWriter(schema)
	bytes_writer = io.BytesIO()
	encoder = avro.io.BinaryEncoder(bytes_writer)
	writer.write({"name": g.generate_sentence(), "favorite_color": g.generate_sentence(), "favorite_number": random.randint(0,10)}, encoder)
	raw_bytes = bytes_writer.getvalue()
	producer.send_messages(topic, raw_bytes)
Ejemplo n.º 4
0
    def create_acts(self):
        """
        Create a bunch of acts.
        """
        # cleanup
        try:
            Act.objects.all().delete()
        except ObjectDoesNotExist:
            pass

        election_date = '2010-06-14'

        g = lipsum.Generator()

        #
        # creazione proposte di delibera di consiglio
        #
        institution = Institution.objects.get(slug='consiglio-comunale')

        for i in range(1, 20):
            d = Deliberation(
                idnum="%s" % i,
                title=g.generate_sentence(),
                text=g.generate_paragraph(),
                presentation_date=datetime.date.today() -
                datetime.timedelta(days=random.randint(1, 10)),
                emitting_institution=institution,
                initiative=Deliberation.INITIATIVE_TYPES.counselor,
            )
            d.save()
            print "Delibera %s - %s creata" % (d.idnum, d.title)

            nf = random.randint(1, 3)
            nc = random.randint(0, 5)
            print "Aggiunta di %s primi firmatari" % nf
            maj = random.choice([
                1, 1, 1, 1, 1, 1, 1, 1, 0
            ])  # first-signers and co-signers come from maj 90% of the times
            presenters = self.get_institution_charges(majority=maj,
                                                      n=(nf + nc))

            for presenter in presenters[0:nf]:
                act_support = ActSupport(
                    charge=presenter,
                    act=d,
                    support_type=ActSupport.SUPPORT_TYPE.first_signer,
                    support_date=d.presentation_date)
                print "%s" % presenter
                act_support.save()

            print "Aggiunta di %s co firmatari" % nc
            for presenter in presenters[nf:]:
                act_support = ActSupport(
                    charge=presenter,
                    act=d,
                    support_type=ActSupport.SUPPORT_TYPE.co_signer,
                    support_date=d.presentation_date)
                print "%s" % presenter
                act_support.save()

            na = random.randint(0, 5)
            print "Aggiunta di %s allegati" % na
            self.generate_random_act_attach(d, n=na)

        for i in range(1, 10):
            a = Interrogation(
                idnum="%s" % i,
                title=g.generate_sentence(),
                text=g.generate_paragraph(),
                presentation_date=datetime.date.today() -
                datetime.timedelta(days=random.randint(1, 10)),
                answer_type=random.choice([i[0]
                                           for i in Interrogation.STATUS]),
                emitting_institution=institution,
            )
            a.save()
            print "Interrogazione %s - %s creata" % (a.idnum, a.title)

        print "ok"
Ejemplo n.º 5
0
 def rand_text(cls):
     g = lipsum.Generator()
     return g.generate_paragraph()
Ejemplo n.º 6
0
def do_db_seed():
    """
    Python based seed data
    """
    mongoengine.connect('%(app_mongodb_db)s' % env,
                        '%(app_mongodb_username)s' % env,
                        '%(app_mongodb_password)s' % env,
                        host='%(app_mongodb_host)s' % env,
                        port=int('%(app_mongodb_port)s' % env))
    
    User.drop_collection()
    Category.drop_collection()
    Question.drop_collection()
    Thread.drop_collection()
    Post.drop_collection()
    SaasConnection.drop_collection()
    
    users = []
    phone = 3155696216
    for f, l in [('matt','wright'),('sundar','raman'),('ethan','holda'),
                 ('philipp','rockell'),('jen','snyder')]:
        phone += 1
        users.append(UserFactory(username=f, 
                                 email='*****@*****.**' % (f, l), 
                                 phoneNumber=str(phone)))
    
    categories = []
    for c in ['Politics', 'Environment', 'Religion', 'World', 'Technology', 'Misc']:
        categories.append(CategoryFactory(name=c))
        
    questions = []
    for q, c, u, a, ed in [('Archived question?',0,0,False, datetime.timedelta(days=-7)),
                           ('Should the legal age to recieve a driver\'s license be raised?',0,0,True, datetime.timedelta(days=7)),
                           ('Does the employment strategy directed to help disadvantaged ethnic minorities constitute racial discrimination?',0,1,False, datetime.timedelta(days=14)),
                           ('Is space exploration a waste of federal tax dollars?',4,2,False, datetime.timedelta(days=21)),
                           ('Should creationism and evolution be taught side by side?',2,3,False, datetime.timedelta(days=28)),]:
        questions.append(QuestionFactory(text=q, category=categories[c], author=users[u], active=a, endDate=datetime.datetime.utcnow() + ed))
        
    threads = []
    for u, yn, t in [(0, 1, 'Too many young drivers are causing a lot of accidents on the road'),
                 (1, 0, 'It\'s fine. You need to start driving at some point.'),
                 (2, 1, 'Yes, their bad driving habits are causing my insurance prices to rise.'),
                 (3, 1, 'It should be raise to 18 just like most goverment priviledges are set to.'),
                 (4, 0, 'The driving age is just fine, there\'s no reason to suddenly change it.'),]:
        
        for i in range(2):
            for n in range(20):
                thread = ThreadFactory(question=questions[i], firstPost=None, postCount=1, yesNo=None, origin='web')
                threads.append(thread)
                thread.firstPost = PostFactory(author=users[u], text=t, yesNo=yn, thread=thread, 
                                               created=datetime.datetime.utcnow() + datetime.timedelta(days=random.randint(-20, 0)))
                thread.created = thread.firstPost.created
                thread.yesNo = thread.firstPost.yesNo
                thread.authorId = thread.firstPost.author.id
                thread.save()
    
    import lipsum
    g = lipsum.Generator()
    
    for n in range(1, len(threads)):
        for i in range(0, random.randint(0, 30)):
            thread = threads[n]
            PostFactory(author=users[random.randint(0,4)], 
                        text=g.generate_paragraph(start_with_lorem=False)[0:random.randint(20, 139)],
                        yesNo=random.randint(0,1),
                        thread=thread,
                        created=thread.created + datetime.timedelta(seconds=i))
            thread.postCount += 1
            thread.save()
            
    user = users[0]
    user.threadSubscription = threads[7]
    user.save()