Exemple #1
0
def add_title(site, count=100):
    print("titles")
    # TODO: Make sure that every slug is unique
    chain = get_chain(site.url, "Titles")
    for _ in range(count):
        title = generate_text(chain, "Titles")
        slug = slugify(title, max_length=70, word_boundary=True)
        Title.create(text=title, slug=slug, site=site)
Exemple #2
0
def add_answer(site, count=300):
    print("answers")
    users = get_unused_users(site, count)
    chain = get_chain(site.url, "Answers")

    for i in range(count):
        text = generate_text(chain, "Answers")
        user = users[i]
        time = datetime.now()
        Answer.create(text=text, user_id=user, site_id=site, datetime=time)
Exemple #3
0
def add_question(site, count=100):
    print("Questions")
    users = get_unused_users(site, count)
    titles = Title.select().join(Question, JOIN.LEFT_OUTER) \
        .where((Title.site == site) & (Question.id.is_null())) \
        .limit(count)
    chain = get_chain(site.url, "Questions")

    for i in range(count):
        text = generate_text(chain, "Questions")
        title = titles[i]
        user = users[i]
        time = datetime.now()
        question = Question.create(text=text,
                                   title_id=title,
                                   user_id=user,
                                   site_id=site,
                                   datetime=time)
        num_answers = random.randint(1, 4)
        answers = Answer.select().where((Answer.site == site) & (
            Answer.question.is_null())).limit(num_answers)
        for answer in answers:
            answer.question = question
            answer.save()
Exemple #4
0
def add_username(site, count=500):
    print("usernames")
    chain = get_chain(site.url, "Usernames")
    for _ in range(count):
        username = generate_text(chain, "Usernames")
        User.create(username=username, site=site)