def other_cn(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_UPPER)
    if random.choice(['just_text', 'structured']) == 'just_text':
        return emitter.emit('text')
    prefix = emitter.emit('string', mn=3, mx=6)
    number = emitter.emit('int', mn=1, mx=999999999)
    return '{} {}'.format(prefix, number)
def sentence_like(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_LOWER)
    words = emitter.emit('text', mn_words=1, mx_words=9).split(' ')
    noun_choice = random.choice([None] * 4 + [person_name_like] * 3 +
                                [place_like, org_name_like])
    year_choice = random.choice([None] * 4 + [year_like])
    wrap_choice = random.choice([None] * 4 + WRAP_PUNCTUATION)
    inner_choices = [random.choice([None] * 2 + INNER_SENTENCE_PUNCTUATION)
                     for _ in range(0, int(len(words) / 2))]
    end_choice = random.choice(END_SENTENCE_PUNCTUATION)

    for choice in (noun_choice, year_choice):
        if choice is not None:
            words.insert(random.randint(0, len(words)),
                         unicode(choice(record)))

    if wrap_choice is not None:
        start, end = wrap_choice
        wrap_index = random.randint(0, len(words) - 1)
        words[wrap_index] = '{}{}{}'.format(start, words[wrap_index], end)

    punct_pos = random.sample(range(0, len(words) - 1), len(inner_choices))
    for i, inner_punct in enumerate(inner_choices):
        if inner_punct is not None:
            punct_index = punct_pos[i]
            words[punct_index] = '{}{}'.format(words[punct_index], inner_punct)
    words[-1] = '{}{}'.format(words[-1], end_choice)
    words[0] = words[0].capitalize()
    return ' '.join(words)
예제 #3
0
def flags(record):
    if 'inventory_date' in record:
        flags = []
        emitter = sf.DataEmitter()
        for _ in range(0, random.randint(0, 3)):
            flags.append(unicode(emitter.emit('string', mn=5, mx=10)))
        return flags or None
def dewey_cn(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_UPPER)
    class_num = emitter.emit('int', mn=100, mx=999)
    class_decimal = emitter.emit('string', mn=1, mx=3, alphabet=NUMBERS)
    cutter = '{}{}'.format(emitter.emit('string', mn=1, mx=2),
                           emitter.emit('int', mn=1, mx=999))
    date = emitter.emit('int', mn=1950, mx=2018)
    return '{}.{} {} {}'.format(class_num, class_decimal, cutter, date)
def place_like(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_LOWER)
    words = emitter.emit('text', mn_words=1, mx_words=4,
                         mn_word_len=3).split(' ')
    comma_index = random.randint(0, len(words) - 1)
    if comma_index < len(words) - 1:
        words[comma_index] = '{},'.format(words[comma_index])
    return ' '.join(words).title()
 def gen(record):
     if should_emit(record):
         emitter, mn = sf.DataEmitter(), None
         for cmpfield in datefields:
             mn = record.get('{}_date'.format(cmpfield), None)
             if mn:
                 break
         return emitter.emit('date', mn=(mn.year, mn.month, mn.day, mn.hour,
                                         mn.minute))
def _make_person_name_parts():
    emitter = sf.DataEmitter(alphabet=LETTERS_LOWER)
    first = emitter.emit('string', mn=1, mx=8)
    middle = emitter.emit('string', mn=3, mx=8)
    last = emitter.emit('string', mn=3, mx=10)
    middle = random.choice(['', middle[0], middle])
    first = '{}.'.format(first) if len(first) == 1 else first
    middle = '{}.'.format(middle) if len(middle) == 1 else middle
    return tuple(part.capitalize() for part in (first, middle, last))
def url_like(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_LOWER)
    host_parts = random.randint(1, 3)
    num_subdirs = random.randint(0, 2)
    host = [emitter.emit('string', mn=3, mx=10) for _ in range(0, host_parts)]
    domain_extension = random.choice(['net', 'com', 'edu'])
    subdirs = [emitter.emit('string', mn=4, mx=10)
               for _ in range(0, num_subdirs)]
    host_string = '.'.join(host + [domain_extension])
    return 'https://{}'.format('/'.join([host_string] + subdirs))
def lc_cn(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_UPPER)
    lcclass = '{}{}'.format(emitter.emit('string', mn=1, mx=2),
                           emitter.emit('int', mn=1, mx=9999))
    cutter = '{}{}'.format(emitter.emit('string', mn=1, mx=2),
                           emitter.emit('int', mn=1, mx=999))
    date = emitter.emit('int', mn=1950, mx=2018)
    if random.choice(['decimal', 'nodecimal']) == 'decimal':
        class_decimal = emitter.emit('string', mn=1, mx=3,
                                     alphabet=NUMBERS)
        lcclass = '{}.{}'.format(lcclass, class_decimal)
    return '{} .{} {}'.format(lcclass, cutter, date)
예제 #10
0
def inventory_notes(record):
    emitter = sf.DataEmitter()

    def format_note(date, msg):
        dstr = '{}-{}-{}T{}:{}:{}Z'.format(date.year, date.month, date.day,
                                           date.hour, date.minute, date.second)
        return unicode('{}|{}').format(dstr, msg)

    def username():
        return unicode(
            emitter.emit('string', mn=4, mx=8, alphabet=tp.LETTERS_LOWER))

    def status_msg(status):
        if status == 'unknown':
            action = 'cleared status'
        else:
            action = 'set status to {}'.format(status)
        return unicode('@SYSTEMLOG-STATUS|{} {}').format(username(), action)

    def flag_msg(flag, action):
        return unicode('@SYSTEMLOG-FLAG|{} {} flag {}').format(
            username(), action, flag)

    def manual_msg():
        msg = emitter.emit('text', mn_words=1, mx_words=5)
        return unicode('{}|{}').format(username(), msg)

    if 'inventory_date' in record:
        notes = []
        d = record['inventory_date']
        notes.append(format_note(d, status_msg(record['shelf_status'])))

        for flag in record.get('flags', []):
            d = emitter.emit('date',
                             mn=(d.year, d.month, d.day, d.hour, d.minute))
            notes.append(format_note(d, flag_msg(flag, 'set')))

        for _ in range(0, random.randint(0, 2)):
            d = emitter.emit('date',
                             mn=(d.year, d.month, d.day, d.hour, d.minute))
            notes.append(format_note(d, manual_msg()))
        return notes
def sudoc_cn(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_UPPER)
    stem = '{} {}.{}'.format(emitter.emit('string', mn=1, mx=2),
                             emitter.emit('int', mn=1, mx=99),
                             emitter.emit('int', mn=1, mx=999))
    if random.choice(['series', 'noseries']) == 'series':
        stem = '{}/{}'.format(stem, emitter.emit('string', mn=1, mx=1,
                                                 alphabet=NUMBERS))
        if random.choice(['dash', 'nodash']) == 'dash':
            stem = '{}-{}'.format(stem, emitter.emit('int', mn=1, mx=9))
    book_choice = random.choice(['', 'book_num', 'cutter'])
    if book_choice == 'book_num':
        book = emitter.emit('int', mn=1, mx=999)
    elif book_choice == 'cutter':
        book = '{} {}'.format(emitter.emit('string', mn=1, mx=2),
                              emitter.emit('int', mn=1, mx=999))
    else:
        book = book_choice
    if book and random.choice(['edition', 'noedition']) == 'edition':
        edition = emitter.emit('int', mn=1, mx=999)
        '{}/{}'.format(book, edition)
    return '{}:{}'.format(stem, book)
예제 #12
0
 def _data_emitter(alphabet=None, emitter_defaults=None):
     return f.DataEmitter(alphabet, emitter_defaults)
def price(record):
    emitter = sf.DataEmitter(alphabet=NUMBERS)
    return '{}.{}'.format(emitter.emit('string', mn=1, mx=3),
                          emitter.emit('string', mn=1, mx=6))
def keyword_like(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_LOWER)
    return emitter.emit('text', mn_words=1, mx_words=4).capitalize()
def org_name_like(record):
    emitter = sf.DataEmitter(alphabet=LETTERS_LOWER)
    return emitter.emit('text', mn_words=1, mx_words=4).title()