Skip to content

Commit

Permalink
added parser for last checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Midnight95 committed Oct 3, 2023
1 parent 3da9da8 commit ae7fec7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions page_analyzer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
Empty file added page_analyzer/config.py
Empty file.
17 changes: 17 additions & 0 deletions page_analyzer/parsers.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ae7fec7

Please sign in to comment.