Skip to content

Commit

Permalink
готово
Browse files Browse the repository at this point in the history
  • Loading branch information
KAnanev committed Jul 13, 2023
1 parent 0c27053 commit 96e1497
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions page_analyzer/services/check_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,30 @@ def check_url(self, url_id):
url_service = URLService(self.db)
url = url_service.get_json_by_id(url_id).name
if url:
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
h1_tag = soup.find('h1').text if soup.find('h1') else None
title = soup.find('title').text if soup.find('title') else None
description_tag = soup.find('meta', attrs={'name': 'description'})

description = description_tag[
'content'] if description_tag else None
response = self.response_check(url)
if response:
return URLChecks(
url_id=url_id,
status_code=response.status_code,
h1=h1_tag,
title=title,
description=description,
status_code=response['status_code'],
h1=response['h1'],
title=response['title'],
description=response['description'],
)

@staticmethod
def response_check(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
h1_tag = soup.find('h1').text if soup.find('h1') else None
title = soup.find('title').text if soup.find('title') else None
description_tag = soup.find('meta', attrs={'name': 'description'})

description = description_tag[
'content'] if description_tag else None

return {
'status_code': response.status_code,
'h1': h1_tag,
'title': title,
'description': description,
}
2 changes: 1 addition & 1 deletion page_analyzer/templates/urls.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</td>
{% if item.url_checks %}
{% for url_checks in item.url_checks %}
<td>{{ url_checks.created_at }}</td>
<td>{{ url_checks.created_at.strftime('%Y-%m-%d') }}</td>
<td>{{ url_checks.status_code }}</td>
{% endfor %}
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ build-backend = "poetry.core.masonry.api"

[tool.flake8]
accept-encodings = "utf-8"
max-complexity = 6
max-complexity = 5
statistics = "False"
max-line-length = 80
enable-extensions = "G"
Expand Down

0 comments on commit 96e1497

Please sign in to comment.