mirror of
https://github.com/FAUSheppy/ths-blowerdoor-raven
synced 2025-12-10 00:38:33 +01:00
add basic functionality
This commit is contained in:
13
data.py
Normal file
13
data.py
Normal file
@@ -0,0 +1,13 @@
|
||||
class BlowerdoorData:
|
||||
def __init__(self, path, docName, location, customer, pdfDate, blowerdoorDate):
|
||||
self.path = path
|
||||
self.docName = docName
|
||||
self.location = location
|
||||
self.customer = customer
|
||||
self.blowerdoorDate = blowerdoorDate
|
||||
self.pdfDate = pdfDate
|
||||
|
||||
|
||||
#print("Bauort: " + location)
|
||||
#print("Bauherr: " + customer)
|
||||
#print("Blowerdoor: " + blowerdoorDate)
|
||||
@@ -1,62 +0,0 @@
|
||||
import fitz
|
||||
import dateutil.parser
|
||||
|
||||
BLOCK_TUP_TEXT = 4
|
||||
doc = fitz.open("Bauablaufplan.pdf")
|
||||
|
||||
FIRST_P = True
|
||||
|
||||
# pop vars
|
||||
customer = "NOT_FOUND"
|
||||
location = ""
|
||||
startDate = doc.metadata["creationDate"].split("D:")[1].split("+")[0]
|
||||
startDateParsed = dateutil.parser.parse(startDate)
|
||||
blowerdoorDate = "NOT_FOUND"
|
||||
|
||||
for p in doc:
|
||||
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 FIRST_P and i < 3 and textNoSpaceNewline:
|
||||
FIRST_P = False
|
||||
customer = text
|
||||
|
||||
if "Bauort:" in text:
|
||||
location += text.split("Bauort:")[1]
|
||||
|
||||
if "Thermoscan" in text:
|
||||
kwParts = text.split("\n")
|
||||
kw = ""
|
||||
title = ""
|
||||
contractor = ""
|
||||
for p in kwParts:
|
||||
pClean = p.strip()
|
||||
if not pClean:
|
||||
continue
|
||||
elif not kw:
|
||||
kw = int(pClean.split(". KW")[0])
|
||||
elif not title:
|
||||
title = pClean
|
||||
elif not contractor:
|
||||
contractor = pClean
|
||||
|
||||
ISO_CAL_KW_LOC = 1
|
||||
kwStartDate = startDateParsed.isocalendar()[ISO_CAL_KW_LOC]
|
||||
if kw < kwStartDate:
|
||||
blowerdoorDate = "{} KW-{} (assumed next year)".format(startDateParsed.year +1, kw)
|
||||
else:
|
||||
blowerdoorDate = "{} KW-{}".format(startDateParsed.year, kw)
|
||||
|
||||
|
||||
|
||||
localtion = location.replace("\n\n", "\n").strip("n")
|
||||
customer = customer.replace("\n \n", "\n").strip("n")
|
||||
customer = customer.replace("\n\n", "\n").strip("n")
|
||||
|
||||
print("Bauort: " + location)
|
||||
print("Bauherr: " + customer)
|
||||
print("Blowerdoor: " + blowerdoorDate)
|
||||
66
eg_geiss_bauherren.py
Normal file
66
eg_geiss_bauherren.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import fitz
|
||||
import data
|
||||
import dateutil.parser
|
||||
import os.path
|
||||
|
||||
|
||||
BLOCK_TUP_TEXT = 4
|
||||
|
||||
def load(filename):
|
||||
doc = fitz.open(filename)
|
||||
FIRST_P = True
|
||||
|
||||
# pop vars
|
||||
customer = "NOT_FOUND"
|
||||
location = ""
|
||||
startDate = doc.metadata["creationDate"].split("D:")[1].split("+")[0]
|
||||
startDateParsed = dateutil.parser.parse(startDate)
|
||||
blowerdoorDate = "NOT_FOUND"
|
||||
|
||||
for p in doc:
|
||||
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 FIRST_P and i < 3 and textNoSpaceNewline:
|
||||
FIRST_P = False
|
||||
customer = text
|
||||
|
||||
if "Bauort:" in text:
|
||||
location += text.split("Bauort:")[1]
|
||||
|
||||
if "Thermoscan" in text:
|
||||
kwParts = text.split("\n")
|
||||
kw = ""
|
||||
title = ""
|
||||
contractor = ""
|
||||
for p in kwParts:
|
||||
pClean = p.strip()
|
||||
if not pClean:
|
||||
continue
|
||||
elif not kw:
|
||||
kw = int(pClean.split(". KW")[0])
|
||||
elif not title:
|
||||
title = pClean
|
||||
elif not contractor:
|
||||
contractor = pClean
|
||||
|
||||
ISO_CAL_KW_LOC = 1
|
||||
kwStartDate = startDateParsed.isocalendar()[ISO_CAL_KW_LOC]
|
||||
if kw < kwStartDate:
|
||||
blowerdoorDate = "{} KW-{}".format(startDateParsed.year +1, kw)
|
||||
else:
|
||||
blowerdoorDate = "{} KW-{}".format(startDateParsed.year, kw)
|
||||
|
||||
|
||||
|
||||
location = location.replace("\n\n", "\n").strip("n")
|
||||
customer = customer.replace("\n \n", "\n").strip("n")
|
||||
customer = customer.replace("\n\n", "\n").strip("n")
|
||||
|
||||
filename = filename.replace("\\","/")
|
||||
return data.BlowerdoorData(filename, os.path.basename(filename), location,
|
||||
customer, startDateParsed, blowerdoorDate)
|
||||
36
server.py
Normal file
36
server.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import flask
|
||||
import argparse
|
||||
import glob
|
||||
import os
|
||||
|
||||
import eg_geiss_bauherren as parserBackend
|
||||
|
||||
app = flask.Flask("THS-Raven")
|
||||
|
||||
@app.route("/")
|
||||
def root():
|
||||
allFiles = []
|
||||
for filename in glob.glob("static/files/*.pdf"):
|
||||
allFiles.append(parserBackend.load(filename))
|
||||
|
||||
return flask.render_template("index.html", listContent=allFiles)
|
||||
|
||||
@app.route("/get-file")
|
||||
def getFile():
|
||||
return flask.send_from_directory("static/files/", flask.request.args.get("basename"), mimetype="application/pdf")
|
||||
|
||||
@app.before_first_request
|
||||
def init():
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Start THS-Raven', \
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('--interface', default="localhost", \
|
||||
help='Interface on which flask (this server) will take requests on')
|
||||
parser.add_argument('--port', default="5000", \
|
||||
help='Port on which flask (this server) will take requests on')
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
app.run(host=args.interface, port=args.port)
|
||||
0
static/files/.gitkeep
Normal file
0
static/files/.gitkeep
Normal file
22
templates/head.html
Normal file
22
templates/head.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<meta charset="utf-8">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="THS-Raven">
|
||||
<meta name="author" content="Yannik Schmidt | https://potaris.de/en/contact">
|
||||
|
||||
<link rel="shortcut icon" href="/defaultFavicon.ico">
|
||||
|
||||
|
||||
<!-- Bootstrap core JS -->
|
||||
<script src="/static/js/jquery.min.js"></script>
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script defer src="/static/js/bootstrap.min.js"></script>
|
||||
|
||||
<!-- mdb -->
|
||||
<link href="/static/css/mdb.min.css" rel="stylesheet">
|
||||
<script defer src="/static/js/mdb.min.js"></script>
|
||||
|
||||
<!-- Custom JS/CSS -->
|
||||
<link href="/static/site.css" rel="stylesheet">
|
||||
43
templates/index.html
Normal file
43
templates/index.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{% include 'head.html' %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% include 'navbar.html' %}
|
||||
<div style="font-size: 16px; font-weight: 300;" class="container mt-5 mb-3" role="main">
|
||||
<table id="tableMain" class="table table-striped table-bordered table-sm"
|
||||
cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="th-sm font-weight-bold">Dokument</th>
|
||||
<th class="th-sm font-weight-bold">Ort</th>
|
||||
<th class="th-sm font-weight-bold">Blowerdoor KW</th>
|
||||
<th class="th-sm font-weight-bold">Bauherr</th>
|
||||
<th class="th-sm font-weight-bold">Dokument Erstellungsdatum</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<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;">{{ bd.location }}</td>
|
||||
<td style="line-height: 45px;">{{ bd.blowerdoorDate }}</td>
|
||||
<td style="line-height: 45px;">{{ bd.customer }}</td>
|
||||
<td style="line-height: 45px;">{{ bd.pdfDate.strftime("%d.%m.%Y") }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script defer>
|
||||
$(document).ready(function () {
|
||||
$('#tableMain').DataTable();
|
||||
$('.dataTables_length').addClass('bs-select');
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
27
templates/navbar.html
Normal file
27
templates/navbar.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
|
||||
<a class="navbar-brand" href="#"></a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar"
|
||||
aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbar">
|
||||
|
||||
<!-- left side -->
|
||||
<ul class="navbar-nav mr-auto">
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/">Home</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<nav id="navbar-ph" class="navbar navbar-dark bg-dark fake">
|
||||
<li class="navbar-nav">
|
||||
<a class="nav-link" href="#">placeholder</a>
|
||||
</li>
|
||||
</nav>
|
||||
Reference in New Issue
Block a user