Skip to content

Commit df59b43

Browse files
committed
data_base.py parser.py url_validator.py
1 parent 490b8ae commit df59b43

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

page_analyzer/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import requests
44
from bs4 import BeautifulSoup
55
from urllib.parse import urlparse
6-
from page_analyzer.data_base import save_url, get_existing_urls, get_db_connection
6+
from page_analyzer.data_base import (save_url, get_existing_urls,
7+
get_db_connection)
78
from page_analyzer.parser import parse_url
89
from page_analyzer.url_validator import validate_url
910

1011

1112
app = Flask(__name__)
1213
app.secret_key = os.getenv('SECRET_KEY')
1314

15+
1416
@app.route('/', methods=['GET'])
1517
def index():
1618
return render_template('index.html')

page_analyzer/data_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def get_db_connection():
1414
def save_url(url):
1515
with get_db_connection() as conn:
1616
with conn.cursor() as cur:
17-
cur.execute('INSERT INTO urls (name) VALUES (%s) RETURNING id', (url,))
17+
cur.execute('INSERT INTO urls (name)'
18+
' VALUES (%s) RETURNING id', (url,))
1819
url_id = cur.fetchone()[0]
1920
conn.commit()
2021
return url_id
2122

23+
2224
def get_existing_urls():
2325
with get_db_connection() as conn:
2426
with conn.cursor() as cur:

page_analyzer/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from urllib.parse import urlparse
22

3+
34
def parse_url(url):
45
parsed_url = urlparse(url.strip())
56
return f"{parsed_url.scheme}://{parsed_url.netloc}"

page_analyzer/url_validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import validators
22

3+
34
def validate_url(url):
45
if not url or len(url) > 255:
56
return "Некорректный URL или превышена длина 255 символов."

0 commit comments

Comments
 (0)