@@ -61,12 +61,10 @@ def create_url():
6161 flash ('Страница уже существует' , 'error' )
6262 return redirect (url_for ('url_detail' , url_id = existing_url [0 ]))
6363
64- # Сохранение нового URL в базу данных
6564 cur .execute ('INSERT INTO urls (name) VALUES (%s) RETURNING id' , (normalized_url ,))
6665 url_id = cur .fetchone ()[0 ]
6766 conn .commit ()
6867 flash ('Страница успешно добавлена' , 'success' )
69-
7068 return redirect (url_for ('url_detail' , url_id = url_id ))
7169
7270
@@ -90,15 +88,15 @@ def list_urls():
9088 return render_template ('urls.html' , urls = urls )
9189
9290
93-
94-
9591@app .route ('/urls/<int:url_id>' , methods = ['GET' ])
9692def url_detail (url_id ):
9793 conn = get_db_connection ()
9894 cursor = conn .cursor ()
9995 cursor .execute ('SELECT * FROM urls WHERE id = %s' , (url_id ,))
10096 url_record = cursor .fetchone ()
101- cursor .execute ('SELECT * FROM url_checks WHERE url_id = %s ORDER BY created_at DESC' , (url_id ,))
97+ cursor .execute ('SELECT * FROM url_checks '
98+ 'WHERE url_id = %s ORDER BY created_at DESC' ,
99+ (url_id ,))
102100 checks = cursor .fetchall ()
103101 cursor .close ()
104102 conn .close ()
@@ -143,15 +141,18 @@ def add_check(url_id):
143141
144142 h1_content = h1_tag .text if h1_tag else None
145143 title_content = title_tag .text if title_tag else None
146- description_content = description_tag ['content' ] if description_tag else None
144+ description_content = description_tag ['content' ] \
145+ if description_tag else None
146+
147147
148- # Записываем код статуса и SEO-данные в базу данных
149148 cur .execute (
150149 '''
151- INSERT INTO url_checks (url_id, status_code, h1, title, description)
150+ INSERT INTO url_checks
151+ (url_id, status_code, h1, title, description)
152152 VALUES (%s, %s, %s, %s, %s)
153153 ''' ,
154- (url_id , response .status_code , h1_content , title_content , description_content )
154+ (url_id , response .status_code , h1_content ,
155+ title_content , description_content )
155156 )
156157
157158 conn .commit ()
0 commit comments