PageRenderTime 36ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/test.py

https://gitlab.com/death-of-the-authors/1942
Python | 147 lines | 98 code | 40 blank | 9 comment | 12 complexity | 472bdc9e60dffcd99e7665646fb67b27 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. # Open all files and do basic cleanup
  9. neel = open('neel.txt', 'r')
  10. neel = neel.read()
  11. neel = neel.replace("\r\n", " ")
  12. neel = neel.replace("\r", " ")
  13. neel = neel.replace("\n", " ")
  14. neel = neel.replace(" ", " ")
  15. neel = neel.replace("\"", " ")
  16. violet = open('violet.txt', 'r')
  17. violet = violet.read()
  18. violet = violet.replace("\r\n", " ")
  19. violet = violet.replace("\r", " ")
  20. violet = violet.replace("\n", " ")
  21. violet = violet.replace(" ", " ")
  22. violet = violet.replace("\"", " ")
  23. # Split text into sentences with help of nltk
  24. sent_tokenizer=nltk.data.load('tokenizers/punkt/english.pickle')
  25. sentences_neel = sent_tokenizer.tokenize(neel)
  26. sent_tokenizer=nltk.data.load('tokenizers/punkt/english.pickle')
  27. sentences_violet = sent_tokenizer.tokenize(violet)
  28. # Intro starts here
  29. cmd = "bash intro.sh"
  30. os.system(cmd)
  31. total = 25
  32. rest = 0
  33. extra = 0
  34. currenttotal = 0
  35. amount_selected_elements = 0
  36. element = "images"
  37. time = 215
  38. delay = time/total
  39. dialogues = (sentences_neel, sentences_violet)
  40. # Let the music start and also loop
  41. cmd = "mplayer -ss 5 blanche/blanche.wav &"
  42. os.system(cmd)
  43. while currenttotal < total:
  44. if element == "images":
  45. amount_selected_elements = randint(1, 3)
  46. if currenttotal + amount_selected_elements > total:
  47. print "stop!"
  48. break
  49. else:
  50. print "currenttotal:", currenttotal, "amount_selected_elements:", amount_selected_elements, "elementtype:", element
  51. z = 1
  52. while z <= amount_selected_elements:
  53. img = str(randint(1, 57)) + ".jpg"
  54. cmd = "feh -x -Z --fullscreen --image-bg black tina/" + img + " &"
  55. os.system(cmd)
  56. sleep(delay)
  57. z += 1
  58. print "image: ", img
  59. currenttotal += amount_selected_elements
  60. element = "texts"
  61. else:
  62. amount_selected_elements = randint(1, 3)
  63. if currenttotal + amount_selected_elements > total:
  64. print "stop!"
  65. break
  66. else:
  67. print "currenttotal:", currenttotal, "amount_selected_elements:", amount_selected_elements, "elementtype:", element
  68. y = 1
  69. while y <= amount_selected_elements:
  70. dialogue = choice(dialogues)
  71. if dialogue == sentences_neel:
  72. colour = "firebrick1"
  73. if dialogue == sentences_violet:
  74. colour = "DodgerBlue"
  75. dialogue_pos = randrange(len(dialogue))
  76. slide = str(dialogue[dialogue_pos])
  77. text_file = open("slide.txt", "w")
  78. text_file.writelines(slide)
  79. text_file.close()
  80. img = "'" + str(y) + "_text.jpg'"
  81. print "text: ", img
  82. 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 + " &"
  83. os.system(cmd)
  84. sleep(delay)
  85. y += 1
  86. currenttotal += amount_selected_elements
  87. element = "images"
  88. print "reached end of the loop"
  89. print "currenttotal:", currenttotal, "elementtype:", element
  90. print "now patch up until you reached total"
  91. while currenttotal < total:
  92. img = str(randint(1, 57)) + ".jpg"
  93. print "image: ", img
  94. cmd = "feh -x -Z --fullscreen --image-bg black tina/" + img + " &"
  95. os.system(cmd)
  96. sleep(delay)
  97. currenttotal += 1
  98. z += 1
  99. print "currenttotal:", currenttotal
  100. # credits start here
  101. cmd = "bash outro.sh"
  102. os.system(cmd)
  103. # really the end
  104. cmd = "killall -w feh; killall -w mplayer"
  105. os.system(cmd)
  106. print 'FIN'
  107. #delay = float(time) / float(i-x)