Beispiel #1
0
    def _dummy_rubric(self):
        """
        Randomly generate a rubric and select options from it.

        Returns:
            rubric (dict)
            options_selected (dict)
        """
        rubric = {'criteria': []}
        options_selected = {}
        words = loremipsum.Generator().words

        for criteria_num in range(self.NUM_CRITERIA):
            criterion = {
                'name': words[criteria_num],
                'prompt': "  ".join(loremipsum.get_sentences(2)),
                'order_num': criteria_num,
                'options': []
            }

            for option_num in range(self.NUM_OPTIONS):
                criterion['options'].append({
                    'order_num': option_num,
                    'points': option_num,
                    'name': words[option_num],
                    'explanation': "  ".join(loremipsum.get_sentences(2))
                })

            rubric['criteria'].append(criterion)
            options_selected[criterion['name']] = criterion['options'][0]['name']

        return rubric, options_selected
def get_subjects():
    subjects_sets = loremipsum.Generator().dictionary
    # keys are the lenght of the contained words
    # let's skip the shortest ones
    set_key = random.choice(subjects_sets.keys()[5:])
    subjects = list(subjects_sets[set_key])
    return subjects
Beispiel #3
0
 def __init__(self):
     logging.basicConfig(format='[%(asctime)s] [%(levelname)s] %(message)s',
                         datefmt='%d/%m/%Y %I:%M:%S %p',
                         level=logging.INFO)
     with open('../../resources/words/words2.txt') as dictionary_text:
         dictionary = dictionary_text.read().split()
     self.LoiGen = loi.Generator(
         sample="The quick brown fox jumps over the lazy dog",
         dictionary=dictionary)
Beispiel #4
0
    def __init__(self, path1, path2):
        """
        FmtCompTester constructor.

        :path1: The path to the first version of GNU's 'fmt' utility.
        :path2: The path to the second version of GNU's 'fmt' utility.
        """
        self.fmt_args = ['-c', '-t', '-s', '-u', '-w', '-g', '-p']
        self.fmt_path1 = path1
        self.fmt_path2 = path2
        self.generator = loremipsum.Generator()
Beispiel #5
0
def gen_sentences(length=80):
    return u'/'.join(
        [s[2] for s in loremipsum.Generator().generate_sentences(length)])
Beispiel #6
0
def gen_sentence():
    return loremipsum.Generator().generate_sentence()[-1]
Beispiel #7
0
def gen_paragraphs(num=3):
    return u'/'.join(
        [p[2] for p in loremipsum.Generator().generate_paragraphs(num)])
def get_text_paragraph():
    return [p[2] for p in loremipsum.Generator().generate_paragraphs(1)][0]
def get_text_line():
    return loremipsum.Generator().generate_sentence()[2]
Beispiel #10
0
def generate_submission(name='post', author=_missing, reply=None,
                        flair=_missing, id_=None):
    """
    Factory for creating a new Submission mock object.
    """
    sub = MagicMock(name=name, spec=praw.models.Submission)
    sub.kind = 't3'
    if author is _missing:
        author = generate_redditor().name
    sub.author = generate_redditor(username=author)
    if not id_:
        id_ = generate_reddit_id()
    sub.id = id_
    sub.shortlink = f'http://redd.it/{sub.id}'

    if flair is _missing:
        flair = 'Unclaimed'
    sub.link_flair_text = flair

    sub.title = ' '.join(random.choices(
        loremipsum.Generator().words,
        k=random.choice(range(1, 5))
    ))

    def make_comment(body):
        out = reply if reply else generate_comment(submission=sub)
        out.parent.return_value = sub
        out.submission = sub
        out.body = body

        return out

    def flair_choices(*args, **kwargs):
        template = {
            'flair_text': 'Foo',
            'flair_template_id': '680f43b8-1fec-11e3-80d1-12313b0b80bc',
            'flair_css_class': '',
            'flair_text_editable': False,
            'flair_position': 'left',
        }
        return [
            {**template,
             **{'flair_text': 'Unclaimed',
                'flair_template_id': '1'},
             },
            {**template,
             **{'flair_text': 'In Progress',
                'flair_template_id': '2'},
             },
            {**template,
             **{'flair_text': 'Completed',
                'flair_template_id': '3'},
             },
            {**template,
             **{'flair_text': 'Meta',
                'flair_template_id': '4'},
             },
        ]

    sub.reply.side_effect = make_comment
    sub.mark_read = MagicMock(side_effect=None)

    sub.flair = MagicMock(
        spec=praw.models.reddit.submission.SubmissionFlair
    )
    sub.flair.choices.side_effect = flair_choices
    sub.flair.select.return_value = None

    return sub
Beispiel #11
0
 def setUp(self):
     self.generator = loremipsum.Generator()
Beispiel #12
0
#!/usr/bin/env python
# https://gist.github.com/jakekdodd/e7ee38fd945818d86eb4
# https://github.com/thanhson1085/python-kafka-avro/blob/master/producer.py

import io
import avro.schema
import avro.io
import loremipsum
import random

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

g = loremipsum.Generator()
url = "HOSTNAME:9092"
kafka = KafkaClient(url)
producer = SimpleProducer(kafka)

# Path to user.avsc avro schema
schema_path = "user.avsc"

# Kafka topic
topic = "my-topic"

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)