From 981e6c7aef981f3b3922338a65aa0346c8ba81ea Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 2 Sep 2022 01:12:54 -0500 Subject: Fixed issues with paragraph parser and simplified code. --- FBGM.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'FBGM.py') diff --git a/FBGM.py b/FBGM.py index 601f509..92c9772 100644 --- a/FBGM.py +++ b/FBGM.py @@ -2,30 +2,34 @@ from ftplib import parse150 import os, sys def paragraph_parser(contents): - paragraph_end = ['.\n', '?\n', '!\n', '"\n'] + paragraph_end = [".\n", "?\n", "!\n", '"\n', "|*E"] paragraph_index = [0] paragraph_number = 1 paragraph = [] x = 0 - while len(paragraph_end) > 1: - while x in range (len(paragraph_end)): - if contents[paragraph_index[paragraph_number-1]:].find(paragraph_end[x]) == -1: - paragraph_end.pop(x) - else: - x += 1 - minimum = contents[paragraph_index[paragraph_number-1]:].index(paragraph_end[0])+paragraph_index[paragraph_number-1] - x = 1 - for x in range (len(paragraph_end)): - if contents[paragraph_index[paragraph_number-1]:].index(paragraph_end[x]) < minimum: - minimum = contents[paragraph_index[paragraph_number-1]:].index(paragraph_end[x])+paragraph_index[paragraph_number-1] - paragraph_index.append(minimum) - print(minimum) - - - - #paragraph.append(contents[paragraph_index[paragraph_number-1]: paragraph_index[paragraph_number]+1]) - #print(paragraph_index[paragraph_number]) + count = 0 + contents=contents.rstrip() + contents+="|*END" + while x in range (len(paragraph_end)): + if contents.find(paragraph_end[x]) == -1: + paragraph_end.pop(x) + else: + count += contents.count(paragraph_end[x]) + x += 1 + while paragraph_end: + minimum = contents[paragraph_index[paragraph_number-1]:].index(paragraph_end[0]) +paragraph_index[paragraph_number-1] + for x in paragraph_end: + if contents[paragraph_index[paragraph_number-1]:].index(x)+paragraph_index[paragraph_number-1]+1 < minimum: + minimum = contents[paragraph_index[paragraph_number-1]:].index(x)+paragraph_index[paragraph_number-1] + paragraph_index.append(minimum+1) + paragraph.append(contents[paragraph_index[paragraph_number-1]+1:paragraph_index[paragraph_number]]) + for x in paragraph_end: + if contents[paragraph_index[paragraph_number]:].find(x) == -1: + paragraph_end.remove(x) paragraph_number +=1 + print(len(paragraph_end)) + print(paragraph) + return @@ -72,7 +76,7 @@ def dochandler(path): #Attempting to pass txt file in path -path = 'C:/Users/a big fuck/Documents/beansandtoast.txt' +path = 'C:/Users/Josh/Desktop/porkandbeans/texttohtml/memes.txt' extension = path[path.rfind('.')+1: len(path)] -- cgit v1.2.3