Commit 1245443f authored by Efi's avatar Efi
Browse files

Merge pull request #1 from makistsantekidis/generator-improvements

Pythonized existing code
parents 5b68fb19 803df4a2
# 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/
#!/usr/bin/python
import random
import argparse
""" Create a random message with 20 words and 5 tags.
......@@ -10,31 +11,22 @@ import random
"""
def main():
filename = '/usr/share/dict/american-english'
lines = list()
hashtags = list()
message = ''
tags = ''
f = open(filename)
for i in range(20):
j = random.randrange(1, 99171)
lines.append(j)
for i in range(5):
j = random.randrange(1, 99171)
hashtags.append(j)
i = 0
for line in f:
if i in lines:
message = message + line.strip() + ' '
if i in hashtags:
tags = tags + '#' + line.strip() + ' '
i += 1
f.close()
print message, tags
def create_random_message():
# Parse arguments
parser = argparse.ArgumentParser(description="Random data generator")
parser.add_argument('--filename', type=str, default='/usr/share/dict/american-english')
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 message, tags
if __name__ == '__main__':
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