mirror of
https://github.com/FAUSheppy/ths-blowerdoor-raven
synced 2025-12-09 16:28:32 +01:00
outdated
This commit is contained in:
5
data.py
5
data.py
@@ -1,11 +1,14 @@
|
|||||||
class BlowerdoorData:
|
class BlowerdoorData:
|
||||||
def __init__(self, path, docName, location, customer, pdfDate, blowerdoorDate):
|
def __init__(self, path, docName, location, customer, pdfDate, blowerdoorDate, inDocumentDate=None):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.docName = docName
|
self.docName = docName
|
||||||
self.location = location
|
self.location = location
|
||||||
self.customer = customer
|
self.customer = customer
|
||||||
self.blowerdoorDate = blowerdoorDate
|
self.blowerdoorDate = blowerdoorDate
|
||||||
self.pdfDate = pdfDate
|
self.pdfDate = pdfDate
|
||||||
|
self.inDocumentDate = inDocumentDate
|
||||||
|
|
||||||
|
self.outdated = False
|
||||||
|
|
||||||
|
|
||||||
#print("Bauort: " + location)
|
#print("Bauort: " + location)
|
||||||
|
|||||||
@@ -14,21 +14,46 @@ def load(filename):
|
|||||||
# pop vars
|
# pop vars
|
||||||
customer = "NOT_FOUND"
|
customer = "NOT_FOUND"
|
||||||
location = ""
|
location = ""
|
||||||
|
inDocumentDate = None
|
||||||
startDate = doc.metadata["creationDate"].split("D:")[1].split("+")[0]
|
startDate = doc.metadata["creationDate"].split("D:")[1].split("+")[0]
|
||||||
startDateParsed = dateutil.parser.parse(startDate)
|
startDateParsed = dateutil.parser.parse(startDate)
|
||||||
blowerdoorDate = "NOT_FOUND"
|
blowerdoorDate = "NOT_FOUND"
|
||||||
|
|
||||||
|
datumNext = False
|
||||||
|
page = -1
|
||||||
for p in doc:
|
for p in doc:
|
||||||
|
page += 1
|
||||||
blocks = p.get_text("blocks")
|
blocks = p.get_text("blocks")
|
||||||
for i in range(0, len(blocks)):
|
for i in range(0, len(blocks)):
|
||||||
|
|
||||||
|
|
||||||
text = blocks[i][BLOCK_TUP_TEXT]
|
text = blocks[i][BLOCK_TUP_TEXT]
|
||||||
|
|
||||||
textNoSpaceNewline = text.replace("\n", "")
|
textNoSpaceNewline = text.replace("\n", "")
|
||||||
textNoSpaceNewline = textNoSpaceNewline.replace(" ", "")
|
textNoSpaceNewline = textNoSpaceNewline.replace(" ", "")
|
||||||
|
|
||||||
|
|
||||||
|
if datumNext and page == 0:
|
||||||
|
try:
|
||||||
|
#if "Bauablaufplan11.pdf" in filename:
|
||||||
|
# print(textNoSpaceNewline)
|
||||||
|
inDocumentDate= dateutil.parser.parse(textNoSpaceNewline)
|
||||||
|
datumNext = False
|
||||||
|
except ValueError:
|
||||||
|
try:
|
||||||
|
split = textNoSpaceNewline.split(".de")[1]
|
||||||
|
inDocumentDate = dateutil.parser.parse(split)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
if FIRST_P and i < 3 and textNoSpaceNewline:
|
if FIRST_P and i < 3 and textNoSpaceNewline:
|
||||||
FIRST_P = False
|
FIRST_P = False
|
||||||
customer = text
|
customer = text
|
||||||
|
|
||||||
|
if "Datum:" in text:
|
||||||
|
datumNext = True
|
||||||
|
|
||||||
if "Bauort:" in text:
|
if "Bauort:" in text:
|
||||||
location += text.split("Bauort:")[1]
|
location += text.split("Bauort:")[1]
|
||||||
@@ -72,4 +97,4 @@ def load(filename):
|
|||||||
|
|
||||||
filename = filename.replace("\\","/")
|
filename = filename.replace("\\","/")
|
||||||
return data.BlowerdoorData(filename, os.path.basename(filename), location,
|
return data.BlowerdoorData(filename, os.path.basename(filename), location,
|
||||||
customer, startDateParsed, blowerdoorDate)
|
customer, startDateParsed, blowerdoorDate, inDocumentDate)
|
||||||
|
|||||||
14
server.py
14
server.py
@@ -15,12 +15,26 @@ def root():
|
|||||||
allFiles = []
|
allFiles = []
|
||||||
loaded = None
|
loaded = None
|
||||||
for filename in glob.glob("static/files/*.pdf"):
|
for filename in glob.glob("static/files/*.pdf"):
|
||||||
|
loaded = parserBackend.load(filename)
|
||||||
try:
|
try:
|
||||||
loaded = parserBackend.load(filename)
|
loaded = parserBackend.load(filename)
|
||||||
except Exception:
|
except Exception:
|
||||||
loaded = BlowerdoorData(os.path.basename(filename), os.path.basename(filename), "", "", datetime.datetime.now(), datetime.datetime.now())
|
loaded = BlowerdoorData(os.path.basename(filename), os.path.basename(filename), "", "", datetime.datetime.now(), datetime.datetime.now())
|
||||||
allFiles.append(loaded)
|
allFiles.append(loaded)
|
||||||
|
|
||||||
|
# check duplicates
|
||||||
|
duplicateCheckMap = dict()
|
||||||
|
for f in allFiles:
|
||||||
|
if f.inDocumentDate:
|
||||||
|
duplicateCheckMap.update({ f.customer + f.location : f })
|
||||||
|
|
||||||
|
for f in allFiles:
|
||||||
|
key = f.customer + f.location
|
||||||
|
if key in duplicateCheckMap and not f is duplicateCheckMap[key]:
|
||||||
|
if f.inDocumentDate <= duplicateCheckMap[key].inDocumentDate:
|
||||||
|
f.outdated = True
|
||||||
|
|
||||||
|
|
||||||
return flask.render_template("index.html", listContent=allFiles)
|
return flask.render_template("index.html", listContent=allFiles)
|
||||||
|
|
||||||
@app.route("/get-file")
|
@app.route("/get-file")
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for bd in listContent %}
|
{% for bd in listContent %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="line-height: 45px;"><a target="_blank" href="/get-file?basename={{ bd.docName }}">{{ bd.docName }}</a></td>
|
<td style="line-height: 45px;"><a target="_blank" href="/get-file?basename={{ bd.docName }}">{{ bd.docName }}</a>
|
||||||
|
{% if bd.outdated %}<p style="color: red;">(älter: {{ bd.inDocumentDate.strftime("%d.%m.%Y") }})</p>{% endif %}
|
||||||
|
</td>
|
||||||
<td style="line-height: 45px;">{{ bd.location }}</td>
|
<td style="line-height: 45px;">{{ bd.location }}</td>
|
||||||
{% if bd.blowerdoorDate %}
|
{% if bd.blowerdoorDate %}
|
||||||
<td style="line-height: 45px;">{{ bd.blowerdoorDate }}</td>
|
<td style="line-height: 45px;">{{ bd.blowerdoorDate }}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user