PageRenderTime 1594ms CodeModel.GetById 28ms RepoModel.GetById 9ms app.codeStats 0ms

/1942.py

https://gitlab.com/death-of-the-authors/1942
Python | 225 lines | 130 code | 62 blank | 33 comment | 17 complexity | 3e0dc171324c4575864333084f424840 MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. from random import *
  5. import nltk
  6. from time import sleep
  7. import sys
  8. from datetime import datetime
  9. import string
  10. # Open all files and do basic cleanup
  11. neel = open('neel.txt', 'r')
  12. neel = neel.read()
  13. neel = neel.replace("\r\n", " ")
  14. neel = neel.replace("\r", " ")
  15. neel = neel.replace("\n", " ")
  16. neel = neel.replace(" ", " ")
  17. neel = neel.replace("\"", " ")
  18. violet = open('violet.txt', 'r')
  19. violet = violet.read()
  20. violet = violet.replace("\r\n", " ")
  21. violet = violet.replace("\r", " ")
  22. violet = violet.replace("\n", " ")
  23. violet = violet.replace(" ", " ")
  24. violet = violet.replace("\"", " ")
  25. # Split text into sentences with help of nltk
  26. sent_tokenizer=nltk.data.load('tokenizers/punkt/english.pickle')
  27. sentences_neel = sent_tokenizer.tokenize(neel)
  28. sent_tokenizer=nltk.data.load('tokenizers/punkt/english.pickle')
  29. sentences_violet = sent_tokenizer.tokenize(violet)
  30. # Limiting amount of words, to avoid illegible slides.
  31. sentences_neel_select = []
  32. sentences_violet_select = []
  33. for sentence_neel in sentences_neel:
  34. words_neel = string.split(sentence_neel)
  35. wordCount = len(words_neel)
  36. if wordCount < 20:
  37. sentences_neel_select.append(sentence_neel)
  38. for sentence_violet in sentences_violet:
  39. words_violet = string.split(sentence_violet)
  40. wordCount = len(words_violet)
  41. if wordCount < 20:
  42. sentences_violet_select.append(sentence_violet)
  43. dialogues = (sentences_neel_select, sentences_violet_select)
  44. total = 22
  45. version = 1
  46. time = 218 # length of blanche.mp3 = 218 sec. Limiting length of sentences made a difference too; less variation.
  47. delay = time/total
  48. # Intro starts here
  49. cmd = "bash intro.sh"
  50. os.system(cmd)
  51. cmd ="convert -background black -bordercolor black -gravity center -fill black -size 1280x800 -border 100 -font OSP-DIN.ttf caption:'Patience please!' intro.jpg;"
  52. os.system(cmd)
  53. cmd="feh -x --fullscreen 'intro.jpg' &"
  54. os.system(cmd)
  55. sleep(delay/2)
  56. # Generated versions start
  57. while version <= 3:
  58. # Reset all counters
  59. starttime=datetime.now()
  60. element = "images"
  61. rest = 0
  62. extra = 0
  63. currenttotal = 0
  64. amount_selected_elements = 0
  65. # Let the music start
  66. cmd = "mplayer -really-quiet blanche/blanche.mp3 &"
  67. os.system(cmd)
  68. # taking out 'version' now (replaced by timestamp)
  69. #cmd ="convert -background black -bordercolor black -gravity center -pointsize 220 -size 1280 -border 100 -fill white -font OSP-DIN.ttf caption:'" + str(version) + "' intro.jpg;"
  70. #os.system(cmd)
  71. #cmd="feh -x --fullscreen 'intro.jpg' &"
  72. #os.system(cmd)
  73. #sleep(delay)
  74. # timestamp
  75. cmd ="convert -background black -bordercolor black -gravity center -pointsize 220 -size 1280 -border 100 -fill white -font OSP-DIN.ttf caption:'" + starttime.ctime() + "' intro.jpg;"
  76. os.system(cmd)
  77. cmd="feh -x --fullscreen 'intro.jpg' &"
  78. os.system(cmd)
  79. sleep(delay)
  80. cmd ="convert -background black -bordercolor black -gravity center -fill black -size 1280x800 -border 100 -font OSP-DIN.ttf caption:'Patience please!' intro.jpg;"
  81. os.system(cmd)
  82. cmd="feh -x --fullscreen 'intro.jpg' &"
  83. os.system(cmd)
  84. sleep(delay/2)
  85. # adding title slides manually to currenttotal
  86. currenttotal = 2
  87. # inner loop starts
  88. while currenttotal < total:
  89. # print "Started inner loop"
  90. if element == "images":
  91. amount_selected_elements = randint(1, 2)
  92. if currenttotal + amount_selected_elements > total:
  93. # print "stop!"
  94. break
  95. else:
  96. # print "currenttotal:", currenttotal, "amount_selected_elements:", amount_selected_elements, "elementtype:", element
  97. z = 1
  98. while z <= amount_selected_elements:
  99. img = str(randint(1, 56)) + ".jpg"
  100. cmd = "feh -x -Z --fullscreen --image-bg black tina/" + img + " &"
  101. os.system(cmd)
  102. sleep(delay)
  103. z += 1
  104. # print "image: ", img
  105. currenttotal += amount_selected_elements
  106. element = "texts"
  107. else:
  108. amount_selected_elements = randint(1, 3)
  109. if currenttotal + amount_selected_elements > total:
  110. # print "stop!"
  111. break
  112. else:
  113. # print "currenttotal:", currenttotal, "amount_selected_elements:", amount_selected_elements, "elementtype:", element
  114. y = 1
  115. while y <= amount_selected_elements:
  116. dialogue = choice(dialogues)
  117. if dialogue == sentences_neel_select:
  118. colour = "firebrick1"
  119. if dialogue == sentences_violet_select:
  120. colour = "DodgerBlue"
  121. dialogue_pos = randrange(len(dialogue))
  122. slide = str(dialogue[dialogue_pos])
  123. text_file = open("slide.txt", "w")
  124. text_file.writelines(slide)
  125. text_file.close()
  126. img = "'" + str(y) + "_text.jpg'"
  127. # print "text: ", img
  128. cmd = "convert -background black -bordercolor black -gravity center -fill " + colour + " -size 1024x768 -border 50 -font OSP-DIN.ttf caption:@slide.txt " + img +"; feh -x --fullscreen " + img + " &"
  129. os.system(cmd)
  130. sleep(delay)
  131. y += 1
  132. currenttotal += amount_selected_elements
  133. element = "images"
  134. # print "this is the end of the main loop"
  135. # print "currenttotal:", currenttotal, "elementtype:", element
  136. # print "now patch up until total reached"
  137. while currenttotal < total:
  138. img = str(randint(1, 56)) + ".jpg"
  139. # print "image: ", img
  140. cmd = "feh -x -Z --fullscreen --image-bg black tina/" + img + " &"
  141. os.system(cmd)
  142. sleep(delay)
  143. currenttotal += 1
  144. z += 1
  145. # measuring length of each remix
  146. endtime=datetime.now()
  147. cmd ="convert -background black -bordercolor black -gravity center -fill black -size 1280x800 -border 100 -font OSP-DIN.ttf caption:'Patience please!' intro.jpg;"
  148. os.system(cmd)
  149. cmd="feh -x --fullscreen 'intro.jpg' &"
  150. os.system(cmd)
  151. sleep(delay)
  152. print "Version:", version, "Duration:", (endtime-starttime).seconds
  153. version += 1
  154. # credits start here
  155. cmd = "bash outro.sh"
  156. os.system(cmd)
  157. # really the end
  158. cmd = "killall -w feh;"
  159. os.system(cmd)
  160. # print 'FIN'
  161. cmd = "clear"
  162. os.system(cmd)
  163. print "FIN"