Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.28 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4.  
  5. def random_title_comment(comment=False):
  6.     with open('words_alpha.txt') as word_file:
  7.         english_words = list(word_file.read().split())
  8.     one_word = random.randint(0, 2)
  9.     text = ''
  10.     if one_word:
  11.         text = english_words[random.randint(0, len(english_words))]
  12.     else:
  13.         for word in range(1, random.randint(1, 4)):
  14.             text = (text + ' ' + english_words[random.randint(0, len(english_words))])[2:]
  15.     return text.capitalize() if comment else text.title()
  16.  
  17.  
  18. def random_author():
  19.     alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  20.     with open('last_names.txt') as last_names_file:
  21.         last_names = list(last_names_file.read().split())
  22.     letters = str(alphabet[random.randint(0, len(alphabet))]) + '.' + str(alphabet[random.randint(0, len(alphabet))])
  23.     last_name = str(last_names[random.randint(0, len(last_names))]).title()
  24.     return letters + '. ' + last_name
  25.  
  26.  
  27. def random_genre():
  28.     with open('genres.txt') as genres_file:
  29.         genres_words = list(genres_file.read().split())
  30.     genre_result = genres_words[random.randint(0, len(genres_words))]
  31.     return genre_result
  32.  
  33.  
  34. def random_year():
  35.     return str(random.randint(1000, 2010))
  36.  
  37.  
  38. def random_isbn():
  39.     return '978-' + str(random.randint(100000000, 9999999999))
  40.  
  41.  
  42. def random_publisher():
  43.     with open('publishers.txt') as publishers_file:
  44.         publishers = list(publishers_file.read().split())
  45.     return publishers[random.randint(0, len(publishers))]
  46.  
  47.  
  48. def random_binding():
  49.     types = ['Hard', 'Soft']
  50.     return types[int(random.randint(1, 3) - 1)]
  51.  
  52.  
  53. def random_source():
  54.     types = ['Gift', 'Purchase', 'Heritage']
  55.     return str(types[int(random.randint(1, 4) - 1)])
  56.  
  57.  
  58. def random_date_appear(publish):
  59.     day = random.randint(1, 32)
  60.     month = random.randint(1, 13)
  61.     year = random.randint(int(publish), 2010)
  62.     day, month = ('0' + str(day)) if day < 10 else day, ('0' + str(month)) if month < 10 else month
  63.     return '{0}.{1}.{2}'.format(day, month, year)
  64.  
  65.  
  66. def random_date_read(appear):
  67.     day = random.randint(1, 32)
  68.     month = random.randint(1, 13)
  69.     year = random.randint(int(appear), 6)
  70.     day, month = ('0' + str(day)) if day < 10 else day, ('0' + str(month)) if month < 10 else month
  71.     return '{0}.{1}.{2}'.format(day, month, year)
  72.  
  73.  
  74. def random_rate():
  75.     return str(int(random.randint(1, 7)) - 1)
  76.  
  77.  
  78. if __name__ == '__main__':
  79.     millis = int(str(round(time.time() * 1000))[4:])
  80.     random.seed(millis)
  81.     title = random_title_comment()
  82.     author = random_author()
  83.     genre = random_genre()
  84.     publish_year = random_year()
  85.     isbn = random_isbn()
  86.     publisher = random_publisher()
  87.     binding = random_binding()
  88.     # source = random_source()
  89.     appear_date = random_date_appear(publish_year)
  90.     # read_date = random_date_read(appear_date[-4::])
  91.     # rate = random_rate()
  92.     # comment = random_title_comment(True)
  93.     string = '{0}|~|{1}|~|{2}|~|{3}|~|{4}|~|{5}|~|{6}|~|{7}|~|{8}|~|{9}|~|{10}|~|{11}|~|0'
  94.     # string = string.format()
  95.     print(title)
  96.     print(author)
  97.     print(genre)
  98.     print(publish_year)
  99.     print(isbn)
  100.     print(publish_year)
  101.     print(binding)
  102.     # print(source)
  103.     print(appear_date)
  104.     # print(read_date)
  105.     # print(rate)
  106.     # print(comment)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement