Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- def random_title_comment(comment=False):
- with open('words_alpha.txt') as word_file:
- english_words = list(word_file.read().split())
- one_word = random.randint(0, 2)
- text = ''
- if one_word:
- text = english_words[random.randint(0, len(english_words))]
- else:
- for word in range(1, random.randint(1, 4)):
- text = (text + ' ' + english_words[random.randint(0, len(english_words))])[2:]
- return text.capitalize() if comment else text.title()
- def random_author():
- alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- with open('last_names.txt') as last_names_file:
- last_names = list(last_names_file.read().split())
- letters = str(alphabet[random.randint(0, len(alphabet))]) + '.' + str(alphabet[random.randint(0, len(alphabet))])
- last_name = str(last_names[random.randint(0, len(last_names))]).title()
- return letters + '. ' + last_name
- def random_genre():
- with open('genres.txt') as genres_file:
- genres_words = list(genres_file.read().split())
- genre_result = genres_words[random.randint(0, len(genres_words))]
- return genre_result
- def random_year():
- return str(random.randint(1000, 2010))
- def random_isbn():
- return '978-' + str(random.randint(100000000, 9999999999))
- def random_publisher():
- with open('publishers.txt') as publishers_file:
- publishers = list(publishers_file.read().split())
- return publishers[random.randint(0, len(publishers))]
- def random_binding():
- types = ['Hard', 'Soft']
- return types[int(random.randint(1, 3) - 1)]
- def random_source():
- types = ['Gift', 'Purchase', 'Heritage']
- return str(types[int(random.randint(1, 4) - 1)])
- def random_date_appear(publish):
- day = random.randint(1, 32)
- month = random.randint(1, 13)
- year = random.randint(int(publish), 2010)
- day, month = ('0' + str(day)) if day < 10 else day, ('0' + str(month)) if month < 10 else month
- return '{0}.{1}.{2}'.format(day, month, year)
- def random_date_read(appear):
- day = random.randint(1, 32)
- month = random.randint(1, 13)
- year = random.randint(int(appear), 6)
- day, month = ('0' + str(day)) if day < 10 else day, ('0' + str(month)) if month < 10 else month
- return '{0}.{1}.{2}'.format(day, month, year)
- def random_rate():
- return str(int(random.randint(1, 7)) - 1)
- if __name__ == '__main__':
- millis = int(str(round(time.time() * 1000))[4:])
- random.seed(millis)
- title = random_title_comment()
- author = random_author()
- genre = random_genre()
- publish_year = random_year()
- isbn = random_isbn()
- publisher = random_publisher()
- binding = random_binding()
- # source = random_source()
- appear_date = random_date_appear(publish_year)
- # read_date = random_date_read(appear_date[-4::])
- # rate = random_rate()
- # comment = random_title_comment(True)
- string = '{0}|~|{1}|~|{2}|~|{3}|~|{4}|~|{5}|~|{6}|~|{7}|~|{8}|~|{9}|~|{10}|~|{11}|~|0'
- # string = string.format()
- print(title)
- print(author)
- print(genre)
- print(publish_year)
- print(isbn)
- print(publish_year)
- print(binding)
- # print(source)
- print(appear_date)
- # print(read_date)
- # print(rate)
- # print(comment)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement