Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 27th, 2014  |  syntax: Python  |  size: 11.25 KB  |  views: 201  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from os import listdir
  2. import operator
  3.  
  4. def get_episode_info():
  5.     ep_list = open("c:\ds9\eplist.txt").readlines()
  6.     episodes = {}
  7.     for episode in ep_list:
  8.         spl = episode.split()
  9.         number = int(spl[0])
  10.         code = spl[1]
  11.         season = code.split("-")[0]
  12.         ep = code.split("-")[1]
  13.         code = "S0" + season + "E" + ep
  14.         airdate = spl[3]
  15.         title = " ".join(spl[4:])
  16.         episodes[400 + number] = [code, airdate, title]
  17.     return episodes
  18.  
  19. def get_top_lines(script, top_speakers):
  20.     ds9script = open("c:/ds9/Scripts - DS9/" + script, "rU")
  21.     dialog = {}
  22.     for line in ds9script.readlines():
  23.         if len(line) > 6:
  24.             if line[:5] == "\t\t\t\t\t" and line[5] != "\t":
  25.                 char = line.strip()
  26.                 try:
  27.                         dialog[char] += 1
  28.                 except KeyError:
  29.                         dialog[char] = 1
  30.     sorted_dialog = sorted(dialog.iteritems(), key=operator.itemgetter(1))
  31.     sorted_dialog.reverse()
  32.     return sorted_dialog[:top_speakers]
  33.    
  34.  
  35. episode_info = get_episode_info()
  36. scripts = listdir("c:/ds9/Scripts - DS9")
  37. scripts.sort()
  38. char = "KIRA"
  39. #scripts = ["402.txt"]
  40. for script in scripts:
  41.     number = int(script.split(".")[0])
  42.     top_lines = get_top_lines(script,1)
  43.     for speaker in top_lines:
  44.         if speaker[0] == char:
  45.             print "* **" + episode_info[number][0] + "** - *" + episode_info[number][2] + "*, Lines: " + str(speaker[1])
  46.    
  47. -- eplist.txt
  48. 2      1-01/02      721       03/Jan/93   Emissary
  49. 3      1-03      404       10/Jan/93   Past Prologue
  50. 4      1-04      403       17/Jan/93   A Man Alone
  51. 5      1-05      405       24/Jan/93   Babel
  52. 6      1-06      406       31/Jan/93   Captive Pursuit
  53. 7      1-07      407       07/Feb/93   Q-Less
  54. 8      1-08      408       14/Feb/93   Dax
  55. 9      1-09      409       21/Feb/93   The Passenger
  56. 10     1-10      410       14/Mar/93   Move Along Home
  57. 11     1-11      411       21/Mar/93   The Nagus
  58. 12     1-12      412       18/Apr/93   Vortex
  59. 13     1-13      413       25/Apr/93   Battle Lines
  60. 14     1-14      414       02/May/93   The Storyteller
  61. 15     1-15      415       09/May/93   Progress
  62. 16     1-16      416       16/May/93   If Wishes Were Horses
  63. 17     1-17      417       23/May/93   The Forsaken
  64. 18     1-18      418       30/May/93   Dramatis Personae
  65. 19     1-19      419       13/Jun/93   Duet
  66. 20     1-20      420       20/Jun/93   In the Hands of the Prophets
  67. 21     2-01      421       26/Sep/93   The Homecoming (1)
  68. 22     2-02      422       03/Oct/93   The Circle (2)
  69. 23     2-03      423       10/Oct/93   The Siege (3)
  70. 24     2-04      424       17/Oct/93   Invasive Procedures
  71. 25     2-05      425       24/Oct/93   Cardassians
  72. 26     2-06      426       31/Oct/93   Melora
  73. 27     2-07      427       07/Nov/93   Rules of Acquisition
  74. 28     2-08      428       14/Nov/93   Necessary Evil
  75. 29     2-09      429       21/Nov/93   Second Sight
  76. 30     2-10      430       28/Nov/93   Sanctuary
  77. 31     2-11      431       02/Jan/94   Rivals
  78. 32     2-12      432       09/Jan/94   The Alternate
  79. 33     2-13      433       30/Jan/94   Armageddon Game
  80. 34     2-14      434       06/Feb/94   Whispers
  81. 35     2-15      435       13/Feb/94   Paradise
  82. 36     2-16      436       20/Feb/94   Shadowplay
  83. 37     2-17      437       27/Feb/94   Playing God
  84. 38     2-18      438       20/Mar/94   Profit and Loss
  85. 39     2-19      439       27/Mar/94   Blood Oath
  86. 40     2-20      440       24/Apr/94   The Maquis, Part I
  87. 41     2-21      441       01/May/94   The Maquis, Part II
  88. 42     2-22      442       08/May/94   The Wire
  89. 43     2-23      443       15/May/94   Crossover
  90. 44     2-24      444       22/May/94   The Collaborator
  91. 45     2-25      445       05/Jun/94   Tribunal
  92. 46     2-26      446       12/Jun/94   The Jem'Hadar (1)
  93. 47     3-01      447       26/Sep/94   The Search, Part I (2)
  94. 48     3-02      448       03/Oct/94   The Search, Part II (3)
  95. 49     3-03      449       16/Oct/94   The House of Quark
  96. 50     3-04      450       23/Oct/94   Equilibrium
  97. 51     3-05      451       30/Oct/94   Second Skin
  98. 52     3-06      452       06/Nov/94   The Abandoned
  99. 53     3-07      453       13/Nov/94   Civil Defense
  100. 54     3-08      454       20/Nov/94   Meridian
  101. 55     3-09      455       27/Nov/94   Defiant
  102. 56     3-10      456       04/Dec/94   Fascination
  103. 57     3-11      457       08/Jan/95   Past Tense, Part I
  104. 58     3-12      458       15/Jan/95   Past Tense, Part II
  105. 59     3-13      459       05/Feb/95   Life Support
  106. 60     3-14      460       12/Feb/95   Heart of Stone
  107. 61     3-15      461       19/Feb/95   Destiny
  108. 62     3-16      462       26/Feb/95   Prophet Motive
  109. 63     3-17      463       05/Mar/95   Visionary
  110. 64     3-18      464       16/Apr/95   Distant Voices
  111. 65     3-19      466       23/Apr/95   Through the Looking Glass
  112. 66     3-20      465       07/May/95   Improbable Cause (1)
  113. 67     3-21      467       07/May/95   The Die is Cast (2)
  114. 68     3-22      468       14/May/95   Explorers
  115. 69     3-23      469       21/May/95   Family Business
  116. 70     3-24      470       28/May/95   Shakaar
  117. 71     3-25      471       18/Jun/95   Facets
  118. 72     3-26      472       25/Jun/95   The Adversary
  119. 73     4-01      473       02/Oct/95   The Way of the Warrior, Part I
  120. 74     4-02      474       02/Oct/95   The Way of the Warrior, Part II
  121. 75     4-03      476       09/Oct/95   The Visitor
  122. 76     4-04      475       16/Oct/95   Hippocratic Oath
  123. 77     4-05      477       23/Oct/95   Indiscretion
  124. 78     4-06      478       30/Oct/95   Rejoined
  125. 79     4-07      479       06/Nov/95   Starship Down
  126. 80     4-08      480       13/Nov/95   Little Green Men
  127. 81     4-09      481       20/Nov/95   The Sword of Kahless
  128. 82     4-10      482       27/Nov/95   Our Man Bashir
  129. 83     4-11      483       01/Jan/96   Homefront (1)
  130. 84     4-12      485       08/Jan/96   Paradise Lost (2)
  131. 85     4-13      485       29/Jan/96   Crossfire
  132. 86     4-14      486       05/Feb/96   Return to Grace
  133. 87     4-15      487       12/Feb/96   Sons of Mogh
  134. 88     4-16      488       19/Feb/96   Bar Association
  135. 89     4-17      489       26/Feb/96   Accession
  136. 90     4-18      490       08/Apr/96   Rules of Engagement
  137. 91     4-19      491       15/Apr/96   Hard Time
  138. 92     4-20      492       22/Apr/96   Shattered Mirror
  139. 93     4-21      493       29/Apr/96   The Muse
  140. 94     4-22      494       06/May/96   For the Cause
  141. 95     4-23      496       13/May/96   To the Death
  142. 96     4-24      495       20/May/96   The Quickening
  143. 97     4-25      497       10/Jun/96   Body Parts
  144. 98     4-26      498       17/Jun/96   Broken Link
  145. 99     5-01      499       30/Sep/96   Apocalypse Rising
  146. 100    5-02      500       07/Oct/96   The Ship
  147. 101    5-03      501       14/Oct/96   Looking for par'Mach in all the Wrong Places
  148. 102    5-04      502       21/Oct/96   ...Nor the Battle to the Strong
  149. 103    5-05      504       28/Oct/96   The Assignment
  150. 104    5-06      503       04/Nov/96   Trials and Tribble-ations
  151. 105    5-07      505       11/Nov/96   Let He Who is Without Sin...
  152. 106    5-08      506       18/Nov/96   Things Past
  153. 107    5-09      507       25/Nov/96   The Ascent
  154. 108    5-10      508       30/Dec/96   Rapture
  155. 109    5-11      509       06/Jan/97   The Darkness and the Light
  156. 110    5-12      510       27/Jan/97   The Begotten
  157. 111    5-13      511       03/Feb/97   For the Uniform
  158. 112    5-14      512       10/Feb/97   In Purgatory's Shadow (1)
  159. 113    5-15      513       17/Feb/97   By Inferno's Light (2)
  160. 114    5-16      514       24/Feb/97   Doctor Bashir, I Presume?
  161. 115    5-17      515       31/Mar/97   A Simple Investigation
  162. 116    5-18      516       07/Apr/97   Business as Usual
  163. 117    5-19      517       14/Apr/97   Ties of Blood and Water
  164. 118    5-20      518       21/Apr/97   Ferengi Love Songs
  165. 119    5-21      519       28/Apr/97   Soldiers of the Empire
  166. 120    5-22      520       05/May/97   Children of Time
  167. 121    5-23      521       12/May/97   Blaze of Glory
  168. 122    5-24      522       19/May/97   Empok Nor
  169. 123    5-25      523       09/Jun/97   In the Cards
  170. 124    5-26      524       16/Jun/97   Call to Arms
  171. 125    6-01      525       29/Sep/97   A Time to Stand
  172. 126    6-02      527       06/Oct/97   Rocks and Shoals
  173. 127    6-03      526       13/Oct/97   Sons and Daughters
  174. 128    6-04      528       20/Oct/97   Behind the Lines
  175. 129    6-05      529       27/Oct/97   Favor the Bold
  176. 130    6-06      530       03/Nov/97   Sacrifice of Angels
  177. 131    6-07      531       10/Nov/97   You are Cordially Invited
  178. 132    6-08      532       17/Nov/97   Resurrection
  179. 133    6-09      533       24/Nov/97   Statistical Probabilities
  180. 134    6-10      534       01/Jan/98   The Magnificent Ferengi
  181. 135    6-11      535       08/Jan/98   Waltz
  182. 136    6-12      536       04/Feb/98   Who Mourns for Morn?
  183. 137    6-13      538       11/Feb/98   Far Beyond the Stars
  184. 138    6-14      537       18/Feb/98   One Little Ship
  185. 139    6-15      539       25/Feb/98   Honor Among Thieves
  186. 140    6-16      540       04/Mar/98   Change of Heart
  187. 141    6-17      541       01/Apr/98   Wrongs Darker than Death or Night
  188. 142    6-18      542       08/Apr/98   Inquisition
  189. 143    6-19      543       15/Apr/98   In the Pale Moonlight
  190. 144    6-20      544       22/Apr/98   His Way
  191. 145    6-21      545       29/Apr/98   The Reckoning
  192. 146    6-22      546       06/May/98   Valiant
  193. 147    6-23      547       13/May/98   Profit and Lace
  194. 148    6-24      548       20/May/98   Time's Orphan
  195. 149    6-25      549       10/Jun/98   The Sound of Her Voice
  196. 150    6-26      550       17/Jun/98   Tears of the Prophets (1)
  197. 151    7-01      551       30/Sep/98   Image in the Sand (2)
  198. 152    7-02      552       07/Oct/98   Shadows and Symbols (3)
  199. 153    7-03      553       14/Oct/98   Afterimage
  200. 154    7-04      554       21/Oct/98   Take Me Out to the Holosuite
  201. 155    7-05      555       28/Oct/98   Chrysalis
  202. 156    7-06      556       04/Nov/98   Treachery, Faith and the Great River
  203. 157    7-07      557       11/Nov/98   Once More Unto the Breach
  204. 158    7-08      558       18/Nov/98   The Siege of AR-558
  205. 159    7-09      559       25/Nov/98   Covenant
  206. 160    7-10      560       30/Dec/98   It's Only a Paper Moon
  207. 161    7-11      561       06/Jan/99   Prodigal Daughter
  208. 162    7-12      562       03/Feb/99   The Emperor's New Cloak
  209. 163    7-13      563       10/Feb/99   Field of Fire
  210. 164    7-14      564       17/Feb/99   Chimera
  211. 165    7-15      566       24/Feb/99   Badda-Bing, Badda-Bang
  212. 166    7-16      565       03/Mar/99   Inter Arma Enim Silent Leges
  213. 167    7-17      567       07/Apr/99   Penumbra
  214. 168    7-18      568       14/Apr/99   'Til Death Do Us Part
  215. 169    7-19      569       21/Apr/99   Strange Bedfellows
  216. 170    7-20      570       28/Apr/99   The Changing Face of Evil
  217. 171    7-21      571       05/May/99   When It Rains...
  218. 172    7-22      572       12/May/99   Tacking into the Wind
  219. 173    7-23      573       19/May/99   Extreme Measures
  220. 174    7-24      574       26/May/99   The Dogs of War
  221. 175    7-25/26      575       02/Jun/99   What You Leave Behind
clone this paste RAW Paste Data