This commit is contained in:
Beppe Vanrolleghem
2018-05-20 19:35:16 +02:00
parent 4721f448f3
commit 02eca5f227
193 changed files with 331 additions and 21 deletions

View File

@@ -1,28 +1,149 @@
import json
import sys, os
Cast = {}
import Analyser
import re
string = sys.argv[1]
temp = ""
arrayOfStrings = []
space = " "
### VARIABLES
Cast = [] #an array of cast members
string = "sys.argv[1]" #the location of the current file we want to convert
temp = "" #temp string
spaces = [] #an array of spaces we want to check since some of the formating is lost and newlines are replaced by a bunch of spaces
spacesRev = []
space = " " #a space var that is used to initiate the spaces list
finishstring = "FINISHEDTHESTRINGS" #finished string meant to check for when we run a huge string through a while loop, when it's done splitting everything, the main string will change name to finishedstring
### VAR INITIATERS
## FILS THE SPACES LIST WITH AMOUNTS OF SPACES WE WILL WANT TO SPLIT FROM.
for x in range(0, 100):
arrayOfStrings.append(space)
space = space+" "
spaces.append(space)
for i in reversed(spaces):
spacesRev.append(i)
### FUNCTIONS
with open(string, "r") as infile:
##SPLITTER
#takes two arguments, the string to split and the array to append the part it split. Checks for any amount of spaces longer then 1 space
def splitter(string, array):
global spacesRev #get all spaces for comparison
global finishstring #get universally set finishstring
index = -1
lowestStart = -1
for space in spaces:
m = re.search(space, string)
if m is not None:
tempStart = m.start()
tempEnd = m.end()
else:
index=-1
continue
if (tempEnd > index or index == -1) and (tempStart <= lowestStart or lowestStart == -1):
index = tempStart
lowestStart = tempEnd
if index > -1:
beforeSplit = string[:index]
afterSplit = string[lowestStart:]
array.append(beforeSplit)
return afterSplit
else:
array.append(string)
return finishstring
def Folder(folder):
global Cast
for file in os.listdir(folder):
if file.endswith(".txt"):
filename = file[:3];
with open(folder+"/"+file, "r") as infile:
fileNaam=infile.read().replace('\n', ' ')
array=fileNaam.split()
arrayFromCast = array[array.index("CAST")+1:]
Cast=arrayFromCast[:arrayFromCast.index("STAR")];
with open('output.json', 'w+') as outfile:
fileNaam = fileNaam.replace('\t', ' ')
x = 0
while fileNaam != finishstring:
fileNaam = splitter(fileNaam, Cast)
if(x < len(fileNaam)) and x is not 0:
break
x = len(fileNaam)
print('only ' + str(x) + " characters left from file " + folder+"/"+file + ", rest is being written to Output/" + folder+"/"+file + '.json')
with open('Output/'+folder+"/"+file+'.json', 'w+') as outfile:
json.dump(Cast, outfile)
with open('Temp.txt', 'w+') as outfile:
outfile.write(temp)
outfile.close()
if "CAST" in Cast:
CheckCast = Cast.index("CAST")
tempAr =Cast[CheckCast:]
if "STAR TREK: THE NEXT GENERATION" in tempAr:
endOfCast = tempAr.index("STAR TREK: THE NEXT GENERATION")
else:
endOfCast = -1
else:
CheckCast = -1
endOfCast = -1
if (CheckCast is not -1) and (endOfCast is not -1):
print(CheckCast)
print(endOfCast)
with open('Output/'+file+'-Casts.json', 'w+') as outfile:
temp = Cast[CheckCast+1:CheckCast+endOfCast]
print(temp)
json.dump(temp, outfile)
Cast = []
def File(file):
global Cast
with open(file, "r") as infile:
fileNaam=infile.read().replace('\n', ' ')
fileNaam = fileNaam.replace('\t', ' ')
x = 0
while fileNaam != finishstring:
fileNaam = splitter(fileNaam, Cast)
if(x < len(fileNaam)) and x is not 0:
break
x = len(fileNaam)
print('only ' + str(x) + " characters left from file " + file + ", rest is being written to Output/" + file + '.json')
with open('Output/'+file+'.json', 'w+') as outfile:
json.dump(Cast, outfile)
if "CAST" in Cast:
CheckCast = Cast.index("CAST")
tempAr =Cast[CheckCast:]
if "STAR TREK: THE NEXT GENERATION" in tempAr:
endOfCast = tempAr.index("STAR TREK: THE NEXT GENERATION")
else:
endOfCast = -1
else:
CheckCast = -1
endOfCast = -1
if (CheckCast is not -1) and (endOfCast is not -1):
print(CheckCast)
print(endOfCast)
with open('Output/'+file+'-Casts.json', 'w+') as outfile:
temp = Cast[CheckCast+1:CheckCast+endOfCast]
print(temp)
json.dump(temp, outfile)
Cast = []
def Main():
if len(sys.argv) > 1:
if (os.path.isdir(sys.argv[1])):
print("folder")
Folder(sys.argv[1])
if (os.path.isfile(sys.argv[1])):
print("file")
File(sys.argv[1])
else:
print("Invalid file")
input()
else:
print('no argument')
input()
Main()

View File

@@ -0,0 +1 @@
["PICARD", "SARAH MACDOUGAL", "RIKER", "JIM SHIMODA", "DATA", "CREWMAN (2)", "TROI", "CREWWOMAN", "BEVERLY", "SECURITY GUARD", "TASHA", "TRANSPORTER CHIEF", "WORF", "CONN", "GEORDI", "WESLEY"]

View File

@@ -0,0 +1 @@
["PICARD", "FIRST EDO CITIZEN", "RIKER", "TWO EDO CITIZENS", "DATA", "RIVAN (YOUNG FEMALE EDO)", "TROI", "LIATOR (MALE EDO)", "BEVERLY", "EDOLORD", "TASHA", "FIRST EDO BOY", "GEORDI", "CONN CREWMEMBER", "WORF", "EDO GIRL", "WESLEY", "SECOND EDO BOY", "FIRST MEDIATOR (MALE EDO)", "SECOND MEDIATOR (MALE EDO)", "EDO", "ADULTS", "CHILDREN", "MUSIC GROUP OF EDO HARPISTS", "TRANSPORTER CHIEF", "MEDICAL TECHNICIAN", "STAR TREK: \"Justice\" - 9/4/87 - SETS"]

View File

@@ -0,0 +1 @@
["PICARD", "FERENGI:", "RIKER", "DAIMON BOK", "BEVERLY", "KAZAGO", "DATA", "RATA", "TROI", "TASHA", "STARGAZER:", "GEORDI", "PHANTOM BRIDGE CREW", "WORF", "VOICES (V.O.)", "WESLEY", "FIRST VOICE (V.O.)", "SECOND VOICE (V.O.)", "THIRD VOICE (V.O.)", "STAR TREK: \"The Battle\" - 9/14/87 - SETS"]

View File

@@ -0,0 +1 @@
["PICARD", "\"Q\"", "RIKER", "WOMAN (SURVIVOR)", "BEVERLY", "BEVERLY", "DATA", "Non-Speaking Roles", "TROI", "CREWMEMBERS", "TASHA", "SICKBAY STAFF", "GEORDI", "TWO SENTRIES", "WORF", "ANIMAL-SOLDIERS", "WESLEY", "DOZEN SURVIVORS", "CHILD (FEMALE SURVIVOR)", "STAR TREK: Hide And \"Q\" - 9/25/87 - SETS"]

View File

@@ -0,0 +1 @@
["PICARD", "HAYNE", "RIKER", "ISHARA YAR", "DATA", "COALITION MAN #1", "BEVERLY", "TAN TSU", "TROI", "GEORDI", "WORF", "Non-Speaking", "VARIOUS TURKANANS", "O'BRIEN", "COALITION MEMBERS", "ALLIANCE MEMBERS", "Non-Speaking", "SUPERNUMERARIES", "STAR TREK: \"Legacy\" - 8/20/90 - SETS"]

View File

@@ -0,0 +1 @@
["PICARD", "K'MPEC", "RIKER", "DURAS", "DATA", "GOWRON", "BEVERLY", "K'EHLEYR", "TROI", "ALEXANDER", "GEORDI", "KLINGON GUARD #1", "WORF", "KLINGON GUARD #2", "TRANSPORTER TECHNICIAN", "SECURITY OFFICER", "Non-Speaking", "Non-Speaking", "SECURITY GUARDS", "4 KLINGON RETAINERS", "2 CHILDREN", "NURSE", "MEDICAL TECHNICIAN", "SUPERNUMERARIES", "STAR TREK: \"Reunion\" - 9/4/90 - SETS"]

View File

@@ -0,0 +1 @@
["PICARD", "ENSIGN JENNA D'SORA", "RIKER", "DATA", "ENSIGN McKNIGHT", "BEVERLY", "TROI", "GEORDI", "WORF", "GUINAN", "O'BRIEN", "KEIKO", "COMPUTER VOICE", "Non-Speaking", "NURSE", "SECURITY OFFICERS", "THORNE", "LIEUTENANT VAN MAYTER", "DATA'S CAT", "SUPERNUMERARIES", "STAR TREK: \"In Theory\" - 3/20/91 - SETS"]

View File

@@ -0,0 +1 @@
["PICARD", "BOK", "RIKER", "JASON", "DATA", "BIRTA", "BEVERLY", "TOL", "TROI", "RHODES", "WORF", "COM VOICE", "GEORDI", "Non-Speaking", "Non-Speaking", "N.D. SUPERNUMERARIES", "N.D FERENGI", "STAR TREK: \"Bloodlines\" - 02/09/94 - SETS"]

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More