diff --git a/README.md b/README.md index 1fb3495..121376d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ### Hexlet tests and linter status: [![Actions Status](https://github.com/Andrey-Barinov/python-project-83/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/Andrey-Barinov/python-project-83/actions) [![Actions Status](https://github.com/Andrey-Barinov/python-project-83/actions/workflows/pyci.yml/badge.svg)](https://github.com/Andrey-Barinov/python-project-83/actions) +[![Maintainability](https://api.codeclimate.com/v1/badges/e0fb12dbfecbfbbae2c5/maintainability)](https://codeclimate.com/github/Andrey-Barinov/python-project-83/maintainability) Page Analyzer is a website that analyzes the specified pages for SEO suitability.
You can try it at the link https://python-project-83-rael.onrender.com
diff --git a/page_analyzer/db.py b/page_analyzer/db.py index c0dff42..55ed129 100644 --- a/page_analyzer/db.py +++ b/page_analyzer/db.py @@ -8,8 +8,12 @@ DATABASE_URL = os.getenv('DATABASE_URL') +def get_connection(): + return psycopg2.connect(DATABASE_URL) + + def add_url_to_db(url): - conn = psycopg2.connect(DATABASE_URL) + conn = get_connection() with conn.cursor() as cur: cur.execute("INSERT INTO urls (name) VALUES (%s)", (url,)) conn.commit() @@ -17,7 +21,7 @@ def add_url_to_db(url): def get_url_by_name(url): - conn = psycopg2.connect(DATABASE_URL) + conn = get_connection() with conn.cursor(cursor_factory=NamedTupleCursor) as cur: cur.execute("SELECT * FROM urls WHERE name = %s", (url,)) @@ -36,7 +40,7 @@ def get_url_by_name(url): def get_url_by_id(url_id): - conn = psycopg2.connect(DATABASE_URL) + conn = get_connection() with conn.cursor(cursor_factory=NamedTupleCursor) as cur: cur.execute("SELECT * FROM urls WHERE id = %s", (url_id,)) @@ -50,7 +54,7 @@ def get_url_by_id(url_id): def get_all_urls_desc(): - conn = psycopg2.connect(DATABASE_URL) + conn = get_connection() with conn.cursor(cursor_factory=NamedTupleCursor) as cur: cur.execute("SELECT * FROM urls ORDER BY id DESC") @@ -64,7 +68,7 @@ def get_all_urls_desc(): def add_check_to_db(url_id, status_code, h1, title, description): - conn = psycopg2.connect(DATABASE_URL) + conn = get_connection() with conn.cursor() as cur: cur.execute("INSERT INTO url_checks (" @@ -82,7 +86,7 @@ def add_check_to_db(url_id, status_code, h1, title, description): def get_url_with_latest_check(): - conn = psycopg2.connect(DATABASE_URL) + conn = get_connection() with conn.cursor(cursor_factory=NamedTupleCursor) as cur: cur.execute(