Use compiled regex in the for
loops for the website
This commit is contained in:
parent
e493eaeb49
commit
20025e02b4
@ -10,6 +10,9 @@ pathSearchMessageParts = sys.argv[2].split(' ')
|
||||
pathSearch = pathSearchMessageParts[1]
|
||||
message = ' '.join(pathSearchMessageParts[2:])
|
||||
|
||||
pathSearchRegex = re.compile(pathSearch)
|
||||
messageRegex = re.compile(message)
|
||||
|
||||
isPathSearchAChannelId = re.match(r'[a-zA-Z0-9-_]{24}', pathSearch)
|
||||
|
||||
searchOnlyCaptions = pathSearchMessageParts[0] == 'search-only-captions'
|
||||
@ -52,14 +55,14 @@ for fileIndex, file in enumerate(files):
|
||||
if searchOnlyCaptions and not endsWithVtt:
|
||||
continue
|
||||
toWrite = f'{file}/{fileInZip}'
|
||||
if not bool(re.search(pathSearch, toWrite)):
|
||||
if not bool(pathSearchRegex.search(toWrite)):
|
||||
continue
|
||||
with zip.open(fileInZip) as f:
|
||||
if endsWithVtt:
|
||||
content = f.read().decode('utf-8')
|
||||
stringIOf = StringIO(content)
|
||||
wholeCaption = ' '.join([cleanCaption(caption.text) for caption in webvtt.read_buffer(stringIOf)])
|
||||
messagePositions = [m.start() for m in re.finditer(message, wholeCaption)]
|
||||
messagePositions = [m.start() for m in messageRegex.finditer(wholeCaption)]
|
||||
if messagePositions != []:
|
||||
timestamps = []
|
||||
for messagePosition in messagePositions:
|
||||
|
Loading…
Reference in New Issue
Block a user