-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaker.py
63 lines (47 loc) · 1.85 KB
/
faker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import json
import os
from random import choice, randint
class DhivehiFaker:
def __init__(self, words_file=None, endings_file=None, sentence_length=None, paragraph_length=None):
if words_file is None:
words_file = 'data/thaana.json'
if endings_file is None:
endings_file = 'data/end.json'
if sentence_length is None:
sentence_length = randint(5, 10)
if paragraph_length is None:
paragraph_length = randint(5, 15)
self.word_list = json.load(open(words_file, encoding="utf-8"))
self.endings_list = json.load(open(endings_file, encoding="utf-8"))
self.sentence_length = sentence_length
self.paragraph_length = paragraph_length
def word(self):
word = choice(self.word_list)
return word
def words(self, count, array=False):
if array:
return [self.word() for _ in range(count)]
words = ""
for _ in range(count):
words += f"{self.word()} "
return words
def sentence(self):
length = self.sentence_length
sentence = f"{self.words(length)} {choice(self.endings_list)}."
return sentence
def sentences(self, count=randint(5, 20), array=False):
if array:
return [self.sentence() for _ in range(count)]
sentence_list = [self.sentence() for _ in range(count)]
sentences = " ".join(sentence_list)
return sentences
def paragraph(self):
length = self.paragraph_length
paragraph = self.sentences(length)
return paragraph
def paragraphs(self, count=randint(5, 10), array=False):
if array:
return [self.paragraph() for _ in range(count)]
paragraph_list = [self.paragraph() for _ in range(count)]
paragraphs = "\n\n".join(paragraph_list)
return paragraphs