Skip to content

Commit

Permalink
stile: Migliora la struttura del codice
Browse files Browse the repository at this point in the history
Le funzioni helper dello script sono posizionate all'inizio.
  • Loading branch information
alterat committed Nov 19, 2017
1 parent dea6403 commit 543abb8
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions normattiva2rst.py
@@ -1,39 +1,14 @@
import re
import sys

filename = sys.argv[1]

latin = ["",
"-bis",
"-ter",
"-quater",
"-quinquies",
"-sexies",
"-septies",
"-octies",
"-novies",
"-decies",
"-undecies",
"-duodecies"]


with open(filename, 'r') as f:
text = f.read().split('\n')

ctxt = [line.strip().replace(" "*5, " ").replace(" "*4, " ").replace(" "*3, " ").replace(" "*2, " ") for line in text]
# === Helper functions

def removeDash(ln):
if re.match(r'----', ln):
return ""
else:
return ln

# replace "((...))" with nothing
ctxt = [line.replace("((...))","") for line in ctxt]
# replace "((" "))" with nothing
ctxt = [line.replace("((","").replace("))","") for line in ctxt]
# replace line with nothing
ctxt = [removeDash(line) for line in ctxt]

def subsAccent(l):
'''
Expand All @@ -51,17 +26,6 @@ def subsAccent(l):

return l

ctxt = [subsAccent(line) for line in ctxt]


new_ctxt = []

for (line, ind) in zip(ctxt, range(len(ctxt))):
if ((line[:4]=="Capo") | (line[:4]=="Sezi") | (line[:4]=="Art.")) & (ctxt[ind-1]!=""):
new_ctxt.append("")
new_ctxt.append(line)



def checkAdd(ln, title, flag):
if ln=="":
Expand All @@ -75,7 +39,6 @@ def checkAdd(ln, title, flag):
return title, flag



def checkLetter(ln):
if ln!="":
for lat in latin:
Expand All @@ -94,6 +57,45 @@ def checkNumber(ln):
else: return False


# === Main script

filename = sys.argv[1]

latin = ["",
"-bis",
"-ter",
"-quater",
"-quinquies",
"-sexies",
"-septies",
"-octies",
"-novies",
"-decies",
"-undecies",
"-duodecies"]


with open(filename, 'r') as f:
text = f.read().split('\n')

ctxt = [line.strip().replace(" "*5, " ").replace(" "*4, " ").replace(" "*3, " ").replace(" "*2, " ") for line in text]
# replace "((...))" with nothing
ctxt = [line.replace("((...))","") for line in ctxt]
# replace "((" "))" with nothing
ctxt = [line.replace("((","").replace("))","") for line in ctxt]
# replace line with nothing
ctxt = [removeDash(line) for line in ctxt]

ctxt = [subsAccent(line) for line in ctxt]


new_ctxt = []

for (line, ind) in zip(ctxt, range(len(ctxt))):
if ((line[:4]=="Capo") | (line[:4]=="Sezi") | (line[:4]=="Art.")) & (ctxt[ind-1]!=""):
new_ctxt.append("")
new_ctxt.append(line)


isArt = 0
isCapo = 0
Expand Down

0 comments on commit 543abb8

Please sign in to comment.