Added Docker configuration
This commit is contained in:
parent
dd7844e094
commit
35679695c5
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
venv
|
||||||
10
Dockerfile
10
Dockerfile
@ -2,15 +2,17 @@ FROM ubuntu:20.04
|
|||||||
|
|
||||||
MAINTAINER Abel Fokkinga "abel@fokkinga.com"
|
MAINTAINER Abel Fokkinga "abel@fokkinga.com"
|
||||||
|
|
||||||
RUN apt-get update -y && \
|
RUN apt-get update && apt-get upgrade -y && apt-get autoremove && apt-get autoclean
|
||||||
apt-get install -y python-pip python-dev
|
RUN apt install git python3 python3-pip -y --no-install-recommends
|
||||||
|
RUN apt install locales -y --no-install-recommends
|
||||||
|
RUN locale-gen en_US.UTF-8
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN pip install flask, requests, wtforms, json
|
RUN pip install flask requests wtforms
|
||||||
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
ENTRYPOINT [ "python" ]
|
ENTRYPOINT [ "python3" ]
|
||||||
|
|
||||||
CMD [ "main.py" ]
|
CMD [ "main.py" ]
|
||||||
|
|||||||
188
main.py
188
main.py
@ -1,94 +1,94 @@
|
|||||||
from flask import Flask, render_template, flash, request
|
from flask import Flask, render_template, flash, request
|
||||||
import requests
|
import requests
|
||||||
from requests import HTTPError
|
from requests import HTTPError
|
||||||
from wtforms import Form, StringField, validators
|
from wtforms import Form, StringField, validators
|
||||||
import json
|
import json
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SECRET_KEY'] = '255771f2872f27567d441f2b62425'
|
app.config['SECRET_KEY'] = '255771f2872f27567d441f2b62425'
|
||||||
|
|
||||||
|
|
||||||
def search_mp(product, postalcode, houseno, houseno_ext=''):
|
def search_mp(product, postalcode, houseno, houseno_ext=''):
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'accept': 'application/json',
|
'accept': 'application/json',
|
||||||
'X-API-Key': config['api_key'],
|
'X-API-Key': config['api_key'],
|
||||||
}
|
}
|
||||||
|
|
||||||
params = (
|
params = (
|
||||||
('product', product),
|
('product', product),
|
||||||
('streetNumber', houseno),
|
('streetNumber', houseno),
|
||||||
('streetNumberAddition', houseno_ext),
|
('streetNumberAddition', houseno_ext),
|
||||||
('postalCode', postalcode),
|
('postalCode', postalcode),
|
||||||
('limit', '50'),
|
('limit', '50'),
|
||||||
('offset', '0'),
|
('offset', '0'),
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(config['endpoint'], headers=headers, params=params)
|
response = requests.get(config['endpoint'], headers=headers, params=params)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except HTTPError as http_err:
|
except HTTPError as http_err:
|
||||||
print(f'HTTP error occurred: {http_err}')
|
print(f'HTTP error occurred: {http_err}')
|
||||||
print(response.status_code)
|
print(response.status_code)
|
||||||
print(response.request.headers)
|
print(response.request.headers)
|
||||||
print(response.headers)
|
print(response.headers)
|
||||||
print(response.text)
|
print(response.text)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f'Other error occurred: {err}')
|
print(f'Other error occurred: {err}')
|
||||||
print(response.text)
|
print(response.text)
|
||||||
else:
|
else:
|
||||||
print('Successfull GET Request')
|
print('Successfull GET Request')
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
def flash_results(results):
|
||||||
def flash_results(results):
|
for mp in results['meteringPoints']:
|
||||||
for mp in results['meteringPoints']:
|
print(mp['specialMeteringPoint'])
|
||||||
result = str(mp['ean']) + ';' + \
|
result = str(mp['ean']) + ';' + \
|
||||||
str(mp['product']) + ';' + \
|
str(mp['product']) + ';' + \
|
||||||
str(mp['address']['street']) + ';' + \
|
str(mp['address']['street']) + ';' + \
|
||||||
str(mp['address']['streetNumber']) + ';' + \
|
str(mp['address']['streetNumber']) + ';' + \
|
||||||
str(mp['address']['streetNumberAddition']) + ';' + \
|
str(mp['address']['streetNumberAddition'] if 'streetNumberAddition' in mp['address'] else '') + ';' + \
|
||||||
str(mp['address']['city']) + ';' + \
|
str(mp['address']['city']) + ';' + \
|
||||||
('Nee' if mp['specialMeteringPoint'] == 'False' else 'Ja') + ';' + \
|
('Nee' if mp['specialMeteringPoint'] is False else 'Ja') + ';' + \
|
||||||
str(mp['organisation']) + ';' + \
|
str(mp['organisation']) + ';' + \
|
||||||
str(mp['gridOperatorEan'])
|
str(mp['gridOperatorEan'])
|
||||||
flash(result, 'results')
|
flash(result, 'results')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class ReusableForm(Form):
|
class ReusableForm(Form):
|
||||||
postalcode = StringField('Postcode:', validators=[validators.InputRequired(), validators.Length(min=6, max=6)])
|
postalcode = StringField('Postcode:', validators=[validators.InputRequired(), validators.Length(min=6, max=6)])
|
||||||
houseno = StringField('Huis nummer:', validators=[validators.InputRequired()])
|
houseno = StringField('Huis nummer:', validators=[validators.InputRequired()])
|
||||||
houseno_ext = StringField('Toevoeging:', validators=[])
|
houseno_ext = StringField('Toevoeging:', validators=[])
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def home():
|
def home():
|
||||||
form = ReusableForm(request.form)
|
form = ReusableForm(request.form)
|
||||||
|
|
||||||
print(form.errors)
|
print(form.errors)
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
postalcode = request.form['postalcode']
|
postalcode = request.form['postalcode']
|
||||||
houseno = request.form['houseno']
|
houseno = request.form['houseno']
|
||||||
houseno_ext = request.form['houseno_ext']
|
houseno_ext = request.form['houseno_ext']
|
||||||
results = search_mp('ELK', postalcode, houseno, houseno_ext)
|
results = search_mp('ELK', postalcode, houseno, houseno_ext)
|
||||||
flash_results(results)
|
flash_results(results)
|
||||||
results = search_mp('GAS', postalcode, houseno, houseno_ext)
|
results = search_mp('GAS', postalcode, houseno, houseno_ext)
|
||||||
flash_results(results)
|
flash_results(results)
|
||||||
|
|
||||||
if form.validate():
|
if form.validate():
|
||||||
# Save the comment here.
|
# Save the comment here.
|
||||||
flash('Op zoek naar ' + postalcode + ' ' + houseno + ' ' + houseno_ext, 'info')
|
flash('Op zoek naar ' + postalcode + ' ' + houseno + ' ' + houseno_ext, 'info')
|
||||||
else:
|
else:
|
||||||
flash('Postcode + huisnummer zijn verplicht.', 'info')
|
flash('Postcode + huisnummer zijn verplicht.', 'info')
|
||||||
return render_template('index.html', form=form)
|
return render_template('index.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/about/')
|
@app.route('/about/')
|
||||||
def about():
|
def about():
|
||||||
return render_template('about.html')
|
return render_template('about.html')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
with open('config.json') as json_data:
|
with open('config.json') as json_data:
|
||||||
config = json.load(json_data)
|
config = json.load(json_data)
|
||||||
app.run(debug=False, host='0.0.0.0')
|
app.run(debug=True, host='0.0.0.0')
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="results">
|
<div class="results">
|
||||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<table class="results">
|
<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>
|
<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 %}
|
{% for category, message in messages %}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user