Fix details parsing
This commit is contained in:
parent
3346c3d37a
commit
06f79d4af8
1 changed files with 18 additions and 12 deletions
|
|
@ -74,7 +74,6 @@ class PdfPage():
|
||||||
details.append(detail)
|
details.append(detail)
|
||||||
detail = Detail()
|
detail = Detail()
|
||||||
split = re.split("(\d)", line, maxsplit=1)
|
split = re.split("(\d)", line, maxsplit=1)
|
||||||
print split
|
|
||||||
detail.price = Decimal(0)
|
detail.price = Decimal(0)
|
||||||
detail.infos = split[1] + split[2]
|
detail.infos = split[1] + split[2]
|
||||||
if '€' in line:
|
if '€' in line:
|
||||||
|
|
@ -112,16 +111,16 @@ class PdfPage():
|
||||||
page = page.split('RÉGLO MOBILE')[0].split('N.B. Prévoir')[0] # remove footers
|
page = page.split('RÉGLO MOBILE')[0].split('N.B. Prévoir')[0] # remove footers
|
||||||
lines = page.split('\n')
|
lines = page.split('\n')
|
||||||
lines = [x for x in lines if len(x) > 0] # Remove empty lines
|
lines = [x for x in lines if len(x) > 0] # Remove empty lines
|
||||||
numitems = (len(lines) + 1) / 5 # Each line has five columns
|
numitems = (len(lines) + 1) / 4 # Each line has five columns
|
||||||
lines.pop(0)
|
lines.pop(0)
|
||||||
modif = 0
|
modif = 0
|
||||||
i = 0
|
i = 0
|
||||||
while i < numitems:
|
while i < numitems:
|
||||||
if modif > 0:
|
if modif != 0:
|
||||||
numitems = ((len(lines) + 1 + modif) / 5)
|
numitems = ((len(lines) + 1 + modif) / 4)
|
||||||
nature = i * 5 - modif
|
nature = i * 4 - modif
|
||||||
dateop = nature + 1
|
dateop = nature
|
||||||
corres = dateop + 1
|
corres = nature + 1
|
||||||
duree = corres + 1
|
duree = corres + 1
|
||||||
price = duree + 1
|
price = duree + 1
|
||||||
|
|
||||||
|
|
@ -129,19 +128,26 @@ class PdfPage():
|
||||||
modif += 1
|
modif += 1
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
if "Votre solde" in lines[nature]:
|
||||||
|
lines[nature + 1] = "Votre solde " + lines[nature + 1]
|
||||||
|
dateop = nature + 1
|
||||||
|
corres = dateop + 1
|
||||||
|
duree = corres + 1
|
||||||
|
price = duree + 1
|
||||||
|
modif -= 1
|
||||||
if not lines[corres][0:3].isdigit() and not lines[corres][0:3] == "-":
|
if not lines[corres][0:3].isdigit() and not lines[corres][0:3] == "-":
|
||||||
modif += 1
|
modif += 1
|
||||||
detail = Detail()
|
detail = Detail()
|
||||||
mydate = date(*reversed([int(x) for x in lines[dateop].split(' ')[0].split("/")]))
|
splits = re.split("(\d+\/\d+\/\d+)", lines[dateop])
|
||||||
mytime = time(*[int(x) for x in lines[dateop].split(' ')[1].split(":")])
|
mydate = date(*reversed([int(x) for x in splits[1].split("/")]))
|
||||||
|
mytime = time(*[int(x) for x in splits[2].split(":")])
|
||||||
detail.datetime = datetime.combine(mydate, mytime)
|
detail.datetime = datetime.combine(mydate, mytime)
|
||||||
if lines[corres] == '-':
|
if lines[corres] == '-':
|
||||||
lines[corres] = ""
|
lines[corres] = ""
|
||||||
if lines[duree] == '-':
|
if lines[duree] == '-':
|
||||||
lines[duree] = ''
|
lines[duree] = ''
|
||||||
detail.label = unicode(lines[nature], encoding='utf-8', errors='replace') + u" " + lines[corres] + u" " + lines[duree]
|
detail.label = unicode(splits[0], encoding='utf-8', errors='replace') + u" " + lines[corres] + u" " + lines[duree]
|
||||||
# Special case with only 4 columns, we insert a price
|
# Special case with only 3 columns, we insert a price
|
||||||
if "Activation de votre ligne" in detail.label:
|
if "Activation de votre ligne" in detail.label:
|
||||||
lines.insert(price, '0')
|
lines.insert(price, '0')
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue