Exemplo n.º 1
0
def widgetgen(maxiter=25):
    """ Generate a set of widgets. """
    wordgen = random_words.RandomWords()
    kinds = 'fizzer', 'buzzer', 'bopper'
    for kind in kinds * maxiter:
        name = wordgen.random_word()
        units = random.randint(0, 100)
        yield Widget(timestamp=randtime(), name=name, kind=kind, units=units)
Exemplo n.º 2
0
def get_random_word():
    rw = random_words.RandomWords()
    return rw.random_word().upper()
Exemplo n.º 3
0
# Kippage Copyright # DO NOT COPY #
# Python 3.6.1 #

# module checking
try:
    import random_words
    import random
except:
    import pip

    pip.main(['install', 'random_words'])
    import random_words
    import random
rw = [x for x in random_words.RandomWords().random_words(None, 5449)]


# CleverBuddy Structure
class CleverBuddy:
    class Settings:
        def DestroyBot(self):
            exec("del CleverBuddy.Bot")

        def Name(name: str):
            CleverBuddy.BotName = name

    class Bot:
        def Talk(text: str):
            if text.lower() in rw:  # 1 word code
                choice = random.choice([1, 2, 3, 4])
                if choice == 1:
                    print(text + ". I know what's that." + ".")
Exemplo n.º 4
0
import random_words
import random

rw = random_words.RandomWords()
word = rw.random_word()

print(word)

ans = random.randint(0, len(word) - 1)
print(ans)

print(word[0:ans], "_", word[ans + 1:len(word)])
playerAnswer = input("please answer: ")

ans1 = word[ans]
if playerAnswer == ans1:
    print("Correct.")
else:
    print("Wrong.")
Exemplo n.º 5
0
def generate_wordlist(length: int = 4,
                      count: int = 2,
                      debug: bool = False,
                      do_sort: bool = True,
                      no_dupes: bool = True,
                      catch_rejected: bool = False):
    """
        
            This function is included mainly for testing without having a puzzle to solve in front of you. There's no 
        guarantee that the items returned will share any letter-places. 
    |  
    
        Return Just a List:
    *******************
    Below is an example of running 'generate_wordlist' with no parameters. (Just using the defaults, hard-coded in)
    
    >>> wl = generate_wordlist()
    ['HUMP', 'PENS']
    
    Below sits yet another example, except this time we're specifying that we want 12 words in our list, each with a
    length of 5 letters.
    
    >>>  wl = generate_wordlist(length=5, count=12)
    ['DOSES', 'EASES', 'GRADE', 'GRAMS', 'HOPES', 'NOSES', 'RAISE', 'SAILS', 'SLAPS', 'SNOWS', 'SPANS', 'WELDS']
    
    
    As shown next, we can even get a bit granular on how that list is returned to us. We can ask it to not bother sorting the list before returning it, like so:
    
    >>> wl = generate_wordlist(length=4, count=20, do_sort=False)
    ['JUGS', 'HELM', 'SLED', 'STEP', 'HUGS', 'BOYS', 'DRIP', 'PANS', 'BOWS', 'FORK', 'MUCH', 'SAIL', 'OHMS', 'ARMY',
    'STOP', 'KITS', 'SALT', 'BUYS', 'DOCK', 'DRIP']
    
    
    >>> wl = generate_wordlist(length=6, count=15, debug=True)
    (['ROUNDS', 'PASSES', 'SWITCH', 'HOISTS', 'CREEKS', 'VIDEOS', 'GROUND', 'FARADS', 'ARREST', 'ROWERS', 'STEAMS',
    'BATTLE', 'SCOPES', 'DAMAGE', 'SAFETY'], 105)
        
        
        :param catch_rejected: 
        :param debug: **[ (bool) | Default: bool(False) ]**
        |  Run in debug mode? If you pass 'bool(True)' to this keyword argument the function will not only return your
        new wordlist but will return a tuple with the first element containing your wordlist, and the second element containing an integer representing the number of words fetched all-together (including words that were not equal to the length parameter).
    |  
        
        :param length: **[(int) | Default: int(4) ]** 
        | The integer representing the length of each the words contained within the list to be returned.
        
    |  
    
        :param count: **[ (int) | Default: int(2) ]**
        |  The integer representing the number of words the list should contain.
    |  
    
        :param do_sort: **[ (bool) | Default: bool(True) ]**
        |  If True (which is the default), the wordlist will be sorted alphabetically before being returned
    | 
    
        :param no_dupes: **[ (bool) | Default: bool(True) ]**
        |  *If True (which is the default)* | The function will check the list to see if a word already exists within the list, not adding it if this is the case.
        |  
        |  *If False* | The function will not process a check for duplicates before adding the word to the list
    
    |   
    """
    # Set some variables to be filled later

    # Create a var to keep track of how many words we grab to get our list (including words that didn't match the
    # length indicated) if the 'debug' parameter is True
    if debug:
        fetched_wcount: int = 0
        fetched_dupes: int = 0
        dupe_dict: dict = {}
        if catch_rejected:
            rej_wl = []
    else:
        if catch_rejected:
            raise UncalledArgumentError('catch-rejected', 'debug')

    w_list = []

    # Instantiate the RandomWords class
    rw = random_words.RandomWords()

    # Have the RandomWords package give us a random word, if it matches the length (in letters) that was asked for
    # upon calling the word will be added to the word list. This loops until 'w_list' has as many entries as
    # requested when called (using the parameter; 'count'
    while len(w_list) < count:

        if debug:
            fetched_wcount += 1

        word = rw.random_word()

        if len(word) == length:

            # If a dupe was found let's check to see if 'debug mode' is active. If so; we'll increment the
            # dupe count by one
            if word in w_list:
                if debug:
                    fetched_dupes += 1
                if not no_dupes:
                    w_list.append(word)
                else:
                    continue
            else:
                w_list.append(word)

        else:
            if catch_rejected and debug:
                rej_wl.append(word)

    if do_sort:
        w_list.sort()

    w_list = prepare_wordlist(w_list)

    if debug:
        stats = {
            "iterations": fetched_wcount,
            "duplicates": fetched_dupes,
            "rejected_words": ''
        }
        if catch_rejected:
            stats['rejected_words'] = rej_wl
        else:
            stats['rejected_words'] = 'Not caught'
        return w_list, stats
    else:
        return w_list
Exemplo n.º 6
0
def build_chunk(shared_labels, uniq_labels, chunk_size, build_time):
    '''
    Builds a chunk that can be converted into a log stream for Loki.
    shared_labels should be a dict with list-of-strings values. The keys will be used as labels,
    and random choices made from the values are used as label values.
    uniq_labels should be a list of tuples. They will be included in each label set, with the first
    entry in each tuple being the label, and the second being the value.
    chunk_size should be an integer telling how many log entries there should be in the chunk.
    build_time should be a floating point value telling how long to sleep (in seconds) while building the chunk
    The chunk is a dict of form
    {
        '{app:"h",uniq1:"0",uniq2:"1"}': [
            {
                'ts': 1565785326.549417,
                'msg': 'the quick brown fox jumped over the lazy dog'
            },
            {
                'ts': 1565785377.3671732,
                'msg': 'hello world'
            }
        ],
        '{app:"j",uniq1:"0",uniq2:"1"}': [
            {
                'ts': 1565785429.616399,
                'msg': 'you can call me ishmael'
            }
        ]
    }
    The messages within each of the streams are guaranteed to be ordered by time,
    as they are appended to the lists with some sleeping in between and the ts is the timestamp at the time of appending.
    uniq1 and uniq2 in the example are the unique labels; they are always the same for all streams.
    '''
    # Split the build_time randomly into chunk_size parts - each part will be the sleeping time between consecutive log entries
    times = [build_time]
    while len(times) < chunk_size:
        index = random.randint(0, len(times) - 1)
        split = random.random()
        times = times[:index] + [times[index]*split, times[index]*(1-split)] + times[index+1:]

    chunk = {}
    rw = random_words.RandomWords()
    for t in times: #len(times) == chunk_size at this point
        time.sleep(t)
        labels = []

        # Generate random values for the shared labels of the log entry
        # For example, if shared_labels is {"hello": ["1", "2"], "world": ["a", "b"]},
        # this could result in 'hello="1"', 'world="b"'
        for k, v in shared_labels.items():
            labels.append("{}=\"{}\"".format(k, random.choice(v)))

        # Include the unique labels
        # For example, if the unique labels are [("uniq0", "0"), ("uniq1", "1")],
        # this will result in 'uniq0="0"', 'uniq1="1"'
        for k, v in uniq_labels:
            labels.append("{}=\"{}\"".format(k, v))

        # Join the labels into a key in the format that loki expects
        key = '{{{}}}'.format(','.join(labels))

        # Generate the actual log entry as a dict in the format of {"ts": <timestamp>, "msg": <message>}
        # and include it under the correct set of labels
        if key not in chunk:
            chunk[key] = []
        wordcount = random.randint(1, 20)
        chunk[key].append({"ts": time.time(), "msg": ' '.join(rw.random_words(count=wordcount))})

    return chunk
Exemplo n.º 7
0
 def generate_books(self):
     book_number = sps.poisson.rvs(5)
     for i in range(book_number):
         self.books.append(Book(random_words.RandomWords().random_word()))
Exemplo n.º 8
0
    "-+-  |\n"
    " |   |\n"
    "     |\n", " +----\n"
    " O   |\n"
    "-+-  |\n"
    " |   |\n"
    "/    |\n", " +----\n"
    " O   |\n"
    "-+-  |\n"
    " |   |\n"
    "/ \  |\n"
]

#word_list = ['HELLO', 'PYTHON', 'FUN', 'COLOR', 'MINECRAFT']
#selected_word = word_list[random.randint(0, len(word_list)) - 1]
selected_word = random_words.RandomWords().random_word().upper()
guess_letters = []
for _ in range(len(selected_word)):
    guess_letters.append('_')
max_guess = len(pictures)
incorrect_guess_count = 0
finish = False
print('Welcome to hangman game.')
while not finish:
    print('Word: ' + ' '.join(guess_letters))

    letter = input('Guess a letter: ')

    if not letter.isalpha():
        print('You did not enter a letter, try again.')
        continue
Exemplo n.º 9
0
class RandomPerson(object):
    nicknames = random_words.RandomNicknames()
    words = random_words.RandomWords()
    emails = random_words.RandomEmails()

    def __init__(self, *args, **kwargs):
        self._zip_code_object = None

    def get_name(self, any_gender=False):
        if any_gender:
            return self.nicknames.random_nick(gender='u')
        return self.nicknames.random_nick(gender='m')

    @property
    def first_name(self):
        return self.get_name(any_gender=True)

    @property
    def last_name(self):
        return self.get_name()

    @property
    def full_name(self):
        return '%s %s' % (self.first_name, self.last_name)

    @property
    def email(self):
        return self.emails.randomMail()

    @property
    def company_name(self):
        if random.choice([True, False]):
            name = RandomCompanyName()
        else:
            name = '%s%s%s' % (RandomCompanyName(), RandomLigature(),
                RandomCompanyName())
        return '%s%s' % (name, RandomCompanySuffix())

    @property
    def address(self):
        number = random.randint(100, 1000)
        name_selector = random.randint(0, 3)
        name_format = '%s Street'
        if name_selector == 0:
            street = name_format % self.first_name
        elif name_selector == 1:
            street = name_format % self.last_name
        elif name_selector == 2:
            street = name_format % self.full_name
        else:
            bits = [self.first_name, self.last_name,
                self.words.random_words()[0].title()]
            street = ' '.join(bits)
        return '%i %s' % (number, street)

    @property
    def zip_code_object(self):
        if self._zip_code_object is None:
            self._zip_code_object = ZipCode.objects.all().order_by('?')[0]
        return self._zip_code_object

    @property
    def zip_code(self):
        return self.zip_code_object.code

    @property
    def city(self):
        return self.zip_code_object.city

    @property
    def state(self):
        return self.zip_code_object.state

    @property
    def country(self):
        return 'US'