Initial version
This commit is contained in:
commit
8973535974
4
config.json
Executable file
4
config.json
Executable file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"endpoint": "https://gateway.edsn.nl/eancodeboek/v1/ecbinfoset",
|
||||
"api_key": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJzZWFyY2htZXRlcmluZ3BvaW50cGJkLnByZC5lZHNuLm5sIiwibWFpbCI6ImZlbmNlcl9ob2xkcy4wd0BpY2xvdWQuY29tIiwibWFpbG9wdGluIjp0cnVlfQ.G2JQoJf448ek33jLqpZX2g9k1ujose3aUoguRLViTb8"
|
||||
}
|
||||
94
main.py
Executable file
94
main.py
Executable file
@ -0,0 +1,94 @@
|
||||
from flask import Flask, render_template, flash, request
|
||||
import requests
|
||||
from requests import HTTPError
|
||||
from wtforms import Form, StringField, validators
|
||||
import json
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = '255771f2872f27567d441f2b62425'
|
||||
|
||||
|
||||
def search_mp(product, postalcode, houseno, houseno_ext=''):
|
||||
|
||||
headers = {
|
||||
'accept': 'application/json',
|
||||
'X-API-Key': config['api_key'],
|
||||
}
|
||||
|
||||
params = (
|
||||
('product', product),
|
||||
('streetNumber', houseno),
|
||||
('streetNumberAddition', houseno_ext),
|
||||
('postalCode', postalcode),
|
||||
('limit', '50'),
|
||||
('offset', '0'),
|
||||
)
|
||||
|
||||
try:
|
||||
response = requests.get(config['endpoint'], headers=headers, params=params)
|
||||
response.raise_for_status()
|
||||
except HTTPError as http_err:
|
||||
print(f'HTTP error occurred: {http_err}')
|
||||
print(response.status_code)
|
||||
print(response.request.headers)
|
||||
print(response.headers)
|
||||
print(response.text)
|
||||
except Exception as err:
|
||||
print(f'Other error occurred: {err}')
|
||||
print(response.text)
|
||||
else:
|
||||
print('Successfull GET Request')
|
||||
return response.json()
|
||||
|
||||
|
||||
def flash_results(results):
|
||||
for mp in results['meteringPoints']:
|
||||
result = str(mp['ean']) + ';' + \
|
||||
str(mp['product']) + ';' + \
|
||||
str(mp['address']['street']) + ';' + \
|
||||
str(mp['address']['streetNumber']) + ';' + \
|
||||
str(mp['address']['streetNumberAddition']) + ';' + \
|
||||
str(mp['address']['city']) + ';' + \
|
||||
('Nee' if mp['specialMeteringPoint'] == 'False' else 'Ja') + ';' + \
|
||||
str(mp['organisation']) + ';' + \
|
||||
str(mp['gridOperatorEan'])
|
||||
flash(result, 'results')
|
||||
return
|
||||
|
||||
|
||||
class ReusableForm(Form):
|
||||
postalcode = StringField('Postcode:', validators=[validators.InputRequired(), validators.Length(min=6, max=6)])
|
||||
houseno = StringField('Huis nummer:', validators=[validators.InputRequired()])
|
||||
houseno_ext = StringField('Toevoeging:', validators=[])
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def home():
|
||||
form = ReusableForm(request.form)
|
||||
|
||||
print(form.errors)
|
||||
if request.method == 'POST':
|
||||
postalcode = request.form['postalcode']
|
||||
houseno = request.form['houseno']
|
||||
houseno_ext = request.form['houseno_ext']
|
||||
results = search_mp('ELK', postalcode, houseno, houseno_ext)
|
||||
flash_results(results)
|
||||
results = search_mp('GAS', postalcode, houseno, houseno_ext)
|
||||
flash_results(results)
|
||||
|
||||
if form.validate():
|
||||
# Save the comment here.
|
||||
flash('Op zoek naar ' + postalcode + ' ' + houseno + ' ' + houseno_ext, 'info')
|
||||
else:
|
||||
flash('Postcode + huisnummer zijn verplicht.', 'info')
|
||||
return render_template('index.html', form=form)
|
||||
|
||||
|
||||
@app.route('/about/')
|
||||
def about():
|
||||
return render_template('about.html')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('config.json') as json_data:
|
||||
config = json.load(json_data)
|
||||
app.run(debug=False)
|
||||
103
static/css/main.css
Executable file
103
static/css/main.css
Executable file
@ -0,0 +1,103 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
color: #444;
|
||||
}
|
||||
/*
|
||||
* Formatting the header area
|
||||
*/
|
||||
header {
|
||||
background-color: #1c3054;;
|
||||
height: 35px;
|
||||
width: 100%;
|
||||
opacity: .9;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
header h1.logo {
|
||||
margin: 0;
|
||||
font-size: 1.7em;
|
||||
color: #fff;
|
||||
text-transform: uppercase;
|
||||
float: left;
|
||||
}
|
||||
header h1.logo:hover {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
/*
|
||||
* Centering the body content
|
||||
*/
|
||||
.container {
|
||||
width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
div.home {
|
||||
padding: 10px 0 30px 0;
|
||||
background-color: lightblue;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
div.form-group {
|
||||
padding: 10px 10px 30px 30px;
|
||||
background-color: #1c3054;
|
||||
color: whitesmoke;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
div.messages {
|
||||
padding: 10px 10px 30px 30px;
|
||||
background-color: #1c3054;
|
||||
color: whitesmoke;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
div.results {
|
||||
padding: 10px 10px 30px 30px;
|
||||
background-color: lightblue;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
div.about {
|
||||
padding: 10px 0 30px 0;
|
||||
background-color: #E6E6FA;
|
||||
-webkit-border-radius: 6px;
|
||||
-moz-border-radius: 6px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 3em;
|
||||
margin-top: 40px;
|
||||
text-align: left;
|
||||
letter-spacing: -2px;
|
||||
}
|
||||
h3 {
|
||||
font-size: 1.7em;
|
||||
font-weight: 100;
|
||||
margin-top: 30px;
|
||||
text-align: left;
|
||||
letter-spacing: -1px;
|
||||
color: #999;
|
||||
}
|
||||
.menu {
|
||||
float: right;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.menu li {
|
||||
display: inline;
|
||||
}
|
||||
.menu li + li {
|
||||
margin-left: 35px;
|
||||
}
|
||||
.menu li a {
|
||||
color: #444;
|
||||
text-decoration: none;
|
||||
}
|
||||
7
templates/about.html
Executable file
7
templates/about.html
Executable file
@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="about">
|
||||
<h1>Zoek je aansluiting</h1>
|
||||
<p>versie 2021-12-17</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
58
templates/index.html
Executable file
58
templates/index.html
Executable file
@ -0,0 +1,58 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="home">
|
||||
<div class="searchMP">
|
||||
<form action="" method="post" role="form">
|
||||
{{ form.csrf }}
|
||||
<div class="form-group">
|
||||
<label for="name">Postcode:</label>
|
||||
<input type="text" class="form-control" id="postcode" name="postalcode" placeholder="Wat is je postcode?">
|
||||
|
||||
<label for="houseno">Huisnummer:</label>
|
||||
<input type="text" class="form-control" id="houseno" name="houseno" placeholder="Wat is je huisnummer?">
|
||||
|
||||
<label for="houseno_ext">Toevoeging:</label>
|
||||
<input type="text" class="form-control" id="houseno_ext" name="houseno_ext" placeholder="een huisnummer toevoeging?">
|
||||
|
||||
<div class="input-submit">
|
||||
<input type="submit" value="Zoek">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<div class="messages">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<ul>
|
||||
{% for category, message in messages %}
|
||||
{% if category == 'info' %}
|
||||
<li>{{ message }}</li>
|
||||
{% endif %}
|
||||
{% endfor %}</ul>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<div class="results">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<table class="results">
|
||||
<tr><th>EAN Aansluiting</th><th>Product</th><th>Straatnaam</th><th>Huisnr.</th><th>Toev.</th><th>Woonplaats</th><th>Bijz. aansl.</th><th>Netbeheerder</th><th>EAN Netbeheerder</th></tr>
|
||||
{% for category, message in messages %}
|
||||
<tr>
|
||||
{% if category == 'results' %}
|
||||
{% set mpr = message.split(';') %}
|
||||
{% for item in mpr %}
|
||||
<td>{{ item }}</td>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
25
templates/layout.html
Executable file
25
templates/layout.html
Executable file
@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Aansluitingenregister</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<h1 class="logo">Zoek je aansluiting</h1>
|
||||
<strong><nav>
|
||||
<ul class="menu">
|
||||
<li><a href="{{ url_for('home') }}">Home</a></li>
|
||||
<li><a href="{{ url_for('about') }}">About</a></li>
|
||||
</ul>
|
||||
</nav></strong>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user