forked from anatoly-scherbakov/geopatterns-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request anatoly-scherbakov#26 from RomanZorkin/Issue#23_ou…
…rselves_random_phrase Issue anatoly-scherbakov#23 Our own text generator
- Loading branch information
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
funny | ||
green | ||
hard | ||
nerdy | ||
wild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
programming | ||
Python | ||
clouds | ||
code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
import loremipsum | ||
import random | ||
|
||
from geopatterns_demo.models import Thesaurus | ||
|
||
|
||
class MakeWord(): | ||
"""Class forms a random word from the transmitted file.""" | ||
|
||
def __init__(self, text_file): | ||
self.text_file = text_file | ||
|
||
def random_word(self): | ||
"""Find random word in text file.""" | ||
with open(self.text_file, 'r') as text: | ||
lines = text.readlines() | ||
# random.choice() is considered to be insecure by flake8-bandit, | ||
# but we're not using this for any kind of cryptographic | ||
# or security related purpose. | ||
return random.choice(lines).rstrip('\n') # noqa: S311 | ||
|
||
|
||
def make_random_text(): | ||
"""Method create random phrase using loremipsum library.""" | ||
return loremipsum.generate(1, 'short') | ||
"""Glues and return a phrase from random words.""" | ||
words_list = [ | ||
MakeWord(file_path.value).random_word() | ||
for file_path in Thesaurus | ||
] | ||
return str(' '.join(words_list)) |