Commit eb3f971d authored by Themis Zamani's avatar Themis Zamani
Browse files

Merge pull request #10 from efikalti/lambda-example

LAM-19 random data generator
parents 3b9b59df e6132fb5
# Created by https://www.gitignore.io
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
ansible/hosts
#!/usr/bin/python
import random
import argparse
""" Create a random message with 20 words and 5 tags.
Create 2 lists, one for the message and one for the tags.
Select 25 random numbers in range 1 - #number of file lines.
Read the file and for each line selected, add it to the appropriate list.
Finally print the message with the tags.
"""
def create_random_message():
# Parse arguments
default_file = '/usr/share/dict/american-english'
parser = argparse.ArgumentParser(description="Random data generator")
parser.add_argument('--filename', type=str, default=default_file)
parser.add_argument('--messages', type=int, default=20)
parser.add_argument('--tags', type=int, default=5)
args = parser.parse_args()
with open(args.filename) as f:
words = f.readlines()
message = ' '.join(
[random.choice(words).strip() for _ in range(args.messages)])
tags = '#' + ' #'.join(
[random.choice(words).strip() for _ in range(args.tags)])
return ' '.join((message,tags))
if __name__ == '__main__':
random_message = create_random_message()
print random_message
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment