mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
43912e02bc
commit
ef9b5a1950
@ -170,12 +170,8 @@ def send_mails(jobnames, callback, attachments, to_s, subjects,
|
||||
# file internal metadata so don't nuke the filename.
|
||||
# https://www.mobileread.com/forums/showthread.php?t=349290
|
||||
aname = f'{uuid4()}.' + aname.rpartition('.')[-1]
|
||||
import random
|
||||
|
||||
from calibre.utils.random_ua import common_english_words, random_english_text
|
||||
words = common_english_words()
|
||||
num_in_subject = random.randrange(3, 9)
|
||||
subject = ' '.join(random.choice(words) for i in range(num_in_subject))
|
||||
from calibre.utils.random_ua import random_english_text
|
||||
subject = random_english_text(min_words_per_sentence=3, max_words_per_sentence=9, max_num_sentences=1).rstrip('.')
|
||||
text = random_english_text()
|
||||
job = ThreadedJob('email', description, gui_sendmail, (attachment, aname, to,
|
||||
subject, text), {}, callback)
|
||||
|
@ -23,13 +23,13 @@ def common_english_words():
|
||||
return ans
|
||||
|
||||
|
||||
def random_english_text():
|
||||
def random_english_text(max_num_sentences=3, min_words_per_sentence=8, max_words_per_sentence=41):
|
||||
import random
|
||||
num_sentences = random.randrange(1, 4)
|
||||
num_sentences = random.randrange(1, max_num_sentences+1)
|
||||
words = common_english_words()
|
||||
|
||||
def sentence():
|
||||
num_words = random.randrange(23, 42)
|
||||
num_words = random.randrange(min_words_per_sentence, max_words_per_sentence+1)
|
||||
return ' '.join(random.choice(words) for i in range(num_words)).capitalize() + '.'
|
||||
return ' '.join(sentence() for i in range(num_sentences))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user