Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checa se site está disponível e se tem bloqueio a robôs #4

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 23.3.0
hooks:
- id: black
language_version: python3.8
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ Monitora portais da transparência de acordo com a LAI e LRF

Lucas da Feira foi um herói do povo negro.
Saiba mais [aqui](https://www.feiradesantana.ba.gov.br/secom/noticias.asp?idn=14154) e [aqui](https://www.feiradesantana.ba.gov.br/servicos.asp?s=a&link=secom/webtv.asp&idv=27031).

## Desenvolvimento

Dependências:

* [playwright](https://playwright.dev/python/docs/intro)
Empty file added lucas/__init__.py
Empty file.
15 changes: 0 additions & 15 deletions lucas/check.py

This file was deleted.

38 changes: 38 additions & 0 deletions lucas/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import requests


def _has_recaptcha(html): # TODO add typing
"""Check if recaptcha is on.

Docs: https://developers.google.com/recaptcha/docs/v3
"""
possibilities = [
html.find("iframe[title^='reCAPTCHA']"),
html.find("input#recaptcha-token"),
html.find("div.g-recaptcha"),
html.find("textarea#g-recaptcha-response"),
html.find("textarea.g-recaptcha-response"),
html.find("script[src*='www.google.com/recaptcha']"),
]
return any(possibilities)


def has_robot_blocker(body):
"""Verify if robot blockers, like recaptcha, are configured."""
return _has_recaptcha(body)


def is_reachable(url):
result = {
"reachable": True,
"robot_friendly": True,
}
response = requests.get(url, timeout=(3.05, 27))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não vai mais ser necessário caso o playwright seja adotado

try:
response.raise_for_status()
except requests.RequestException:
result["reachable"] = False
else:
if has_robot_blocker(response.text):
result["robot_friendly"] = False
return result
22 changes: 22 additions & 0 deletions lucas/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from lucas.checks import is_reachable

config = {
"portal": "http://www.transparencia.feiradesantana.ba.gov.br/",
"despesas": "http://www.transparencia.feiradesantana.ba.gov.br/index.php?view=despesa",
"receitas": "http://www.transparencia.feiradesantana.ba.gov.br/index.php?view=receita",
"licitacoes": "http://www.transparencia.feiradesantana.ba.gov.br/index.php?view=licitacoes",
"contratos": "http://www.transparencia.feiradesantana.ba.gov.br/index.php?view=contratos",
}


def main():
print("Acessível?")
for key, url in config.items():
print(f"{key} - {url}")
result = is_reachable(url)
for criteria, criteria_result in result.items():
print(f"- {criteria} {'✅' if criteria_result else '❌'}")


if __name__ == "__main__":
main()
498 changes: 497 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ authors = ["Ana Paula Gomes <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.scripts]
lucas = "lucas.cli:main"

[tool.poetry.dependencies]
python = "^3.8"
requests = "^2.28.2"
bs4 = "^0.0.1"
ipython = "^8.12.0"
pytest-playwright = "^0.3.2"


[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
pytest-mock = "^3.10.0"
requests-mock = "^1.10.0"
pre-commit = "^3.2.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
markers = [
"rules: marca um teste como uma regra (pule-os com '-m \"not rules\"')",
]
Loading