From 491b2ea40ea21316c9ef3da72d865f369f6beafb Mon Sep 17 00:00:00 2001 From: Daniel Behmer Date: Thu, 1 Sep 2022 11:46:48 -0700 Subject: Added paragraph parser --in progress --- FBGM.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'FBGM.py') diff --git a/FBGM.py b/FBGM.py index e36457f..601f509 100644 --- a/FBGM.py +++ b/FBGM.py @@ -1,23 +1,57 @@ from ftplib import parse150 import os, sys +def paragraph_parser(contents): + paragraph_end = ['.\n', '?\n', '!\n', '"\n'] + 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]) + paragraph_number +=1 + + + + def txthandler(path, htmlfile): + filename = path[path.rfind('/')+1: path.rfind('.')] f = open(path, "r") contents = f.read() + title = filename + main_header = contents[0:contents.find('\n')] + paragraph_parser(contents) + htmlfile.write('' '' '' - '' +filename+ '' + '' +title+ '' '' '' '' '' '' - '

' +contents[0:contents.find('\n')]+ '

' + '

' +main_header+ '

' '
' '

  Introduction  

' - '

'+contents[contents.find('\n'):contents[contents.find('\n'):].find('.\n')+contents.find('\n')+1]+'

' + '

''

' '
' '' '') -- cgit v1.2.3