commit 8973535974064376b70e8f396f21b12e280a911e Author: Abel Date: Fri Dec 31 14:11:04 2021 +0100 Initial version diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/config.json b/config.json new file mode 100755 index 0000000..6053cb1 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "endpoint": "https://gateway.edsn.nl/eancodeboek/v1/ecbinfoset", + "api_key": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJzZWFyY2htZXRlcmluZ3BvaW50cGJkLnByZC5lZHNuLm5sIiwibWFpbCI6ImZlbmNlcl9ob2xkcy4wd0BpY2xvdWQuY29tIiwibWFpbG9wdGluIjp0cnVlfQ.G2JQoJf448ek33jLqpZX2g9k1ujose3aUoguRLViTb8" +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100755 index 0000000..81612b2 --- /dev/null +++ b/main.py @@ -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) diff --git a/static/css/main.css b/static/css/main.css new file mode 100755 index 0000000..fbdf0c8 --- /dev/null +++ b/static/css/main.css @@ -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; +} \ No newline at end of file diff --git a/templates/about.html b/templates/about.html new file mode 100755 index 0000000..18c6763 --- /dev/null +++ b/templates/about.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} +{% block content %} +
+

Zoek je aansluiting

+

versie 2021-12-17

+
+ {% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100755 index 0000000..1329bc6 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,58 @@ +{% extends "layout.html" %} +{% block content %} +
+
+
+ {{ form.csrf }} +
+ + + + + + + + + +
+ +
+ +
+ +
+
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} +
    + {% for category, message in messages %} + {% if category == 'info' %} +
  • {{ message }}
  • + {% endif %} + {% endfor %}
+ {% endif %} + {% endwith %} +
+
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + + + {% for category, message in messages %} + + {% if category == 'results' %} + {% set mpr = message.split(';') %} + {% for item in mpr %} + + {% endfor %} + {% endif %} + + {% endfor %} +
EAN AansluitingProductStraatnaamHuisnr.Toev.WoonplaatsBijz. aansl.NetbeheerderEAN Netbeheerder
{{ item }}
+ {% endif %} + {% endwith %} +
+
+
+{% endblock %} + diff --git a/templates/layout.html b/templates/layout.html new file mode 100755 index 0000000..515fb1e --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,25 @@ + + + + + Aansluitingenregister + + + +
+
+

Zoek je aansluiting

+ +
+
+
+ {% block content %} + {% endblock %} +
+ + \ No newline at end of file