diff --git a/page_analyzer/app.py b/page_analyzer/app.py index ec2a3b9..0ea44d8 100644 --- a/page_analyzer/app.py +++ b/page_analyzer/app.py @@ -16,6 +16,8 @@ from validators.url import url from page_analyzer.db import Database +from page_analyzer.parsers import get_last_status_codes + load_dotenv() db_url = os.getenv('DATABASE_URL') @@ -46,11 +48,12 @@ def index(): return render_template('index.html') -@app.get('/urls/') +@app.get('/urls') def get_urls(): with Database(db_url) as db: sites = db.render(table='urls') - return render_template('urls.html', sites=sites) + checks = get_last_status_codes(db.render(table='urls_checks')) + return render_template('urls.html', sites=sites, checks=checks) @app.post('/urls') diff --git a/page_analyzer/config.py b/page_analyzer/config.py new file mode 100644 index 0000000..e69de29 diff --git a/page_analyzer/parsers.py b/page_analyzer/parsers.py new file mode 100644 index 0000000..346e614 --- /dev/null +++ b/page_analyzer/parsers.py @@ -0,0 +1,17 @@ + +def get_last_status_codes(checks): + result = {} + + for item in checks: + id = item['id'] + url_id = item['url_id'] + + if url_id not in result or result.get(url_id, {}).get('id', -1) < id: + result[url_id] = { + 'id': id, + 'status_code': item['status_code'], + 'created_at': item['created_at'] + } + + return result +