File tree Expand file tree Collapse file tree 4 files changed +8
-2
lines changed Expand file tree Collapse file tree 4 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 33import requests
44from bs4 import BeautifulSoup
55from 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 )
78from page_analyzer .parser import parse_url
89from page_analyzer .url_validator import validate_url
910
1011
1112app = Flask (__name__ )
1213app .secret_key = os .getenv ('SECRET_KEY' )
1314
15+
1416@app .route ('/' , methods = ['GET' ])
1517def index ():
1618 return render_template ('index.html' )
Original file line number Diff line number Diff line change @@ -14,11 +14,13 @@ def get_db_connection():
1414def 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+
2224def get_existing_urls ():
2325 with get_db_connection () as conn :
2426 with conn .cursor () as cur :
Original file line number Diff line number Diff line change 11from urllib .parse import urlparse
22
3+
34def parse_url (url ):
45 parsed_url = urlparse (url .strip ())
56 return f"{ parsed_url .scheme } ://{ parsed_url .netloc } "
Original file line number Diff line number Diff line change 11import validators
22
3+
34def validate_url (url ):
45 if not url or len (url ) > 255 :
56 return "Некорректный URL или превышена длина 255 символов."
You can’t perform that action at this time.
0 commit comments