mirror of
https://github.com/FAUSheppy/ths-blowerdoor-raven
synced 2025-12-06 06:51:36 +01:00
outdated
This commit is contained in:
5
data.py
5
data.py
@@ -1,11 +1,14 @@
|
||||
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.docName = docName
|
||||
self.location = location
|
||||
self.customer = customer
|
||||
self.blowerdoorDate = blowerdoorDate
|
||||
self.pdfDate = pdfDate
|
||||
self.inDocumentDate = inDocumentDate
|
||||
|
||||
self.outdated = False
|
||||
|
||||
|
||||
#print("Bauort: " + location)
|
||||
|
||||
@@ -14,22 +14,47 @@ def load(filename):
|
||||
# pop vars
|
||||
customer = "NOT_FOUND"
|
||||
location = ""
|
||||
inDocumentDate = None
|
||||
startDate = doc.metadata["creationDate"].split("D:")[1].split("+")[0]
|
||||
startDateParsed = dateutil.parser.parse(startDate)
|
||||
blowerdoorDate = "NOT_FOUND"
|
||||
|
||||
datumNext = False
|
||||
page = -1
|
||||
for p in doc:
|
||||
page += 1
|
||||
blocks = p.get_text("blocks")
|
||||
for i in range(0, len(blocks)):
|
||||
|
||||
|
||||
text = blocks[i][BLOCK_TUP_TEXT]
|
||||
|
||||
textNoSpaceNewline = text.replace("\n", "")
|
||||
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:
|
||||
FIRST_P = False
|
||||
customer = text
|
||||
|
||||
if "Datum:" in text:
|
||||
datumNext = True
|
||||
|
||||
if "Bauort:" in text:
|
||||
location += text.split("Bauort:")[1]
|
||||
|
||||
@@ -72,4 +97,4 @@ def load(filename):
|
||||
|
||||
filename = filename.replace("\\","/")
|
||||
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 = []
|
||||
loaded = None
|
||||
for filename in glob.glob("static/files/*.pdf"):
|
||||
loaded = parserBackend.load(filename)
|
||||
try:
|
||||
loaded = parserBackend.load(filename)
|
||||
except Exception:
|
||||
loaded = BlowerdoorData(os.path.basename(filename), os.path.basename(filename), "", "", datetime.datetime.now(), datetime.datetime.now())
|
||||
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)
|
||||
|
||||
@app.route("/get-file")
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
<tbody>
|
||||
{% for bd in listContent %}
|
||||
<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>
|
||||
{% if bd.blowerdoorDate %}
|
||||
<td style="line-height: 45px;">{{ bd.blowerdoorDate }}</td>
|
||||
|
||||
Reference in New Issue
Block a user