-
Notifications
You must be signed in to change notification settings - Fork 0
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
anapaulagomes
wants to merge
6
commits into
main
Choose a base branch
from
checagem-basica-lrf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfbf7f0
Add testes para is_reachable
anapaulagomes 6cb05db
Add pre-commit
anapaulagomes 1e3ca2d
Add pacote como CLI
anapaulagomes fa95293
[WIP] Checa se tem recaptcha ou não
anapaulagomes 1d67c7a
Adiciona testes para receitas e contratos com playwright
anapaulagomes 75d8546
WIP
anapaulagomes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
try: | ||
response.raise_for_status() | ||
except requests.RequestException: | ||
result["reachable"] = False | ||
else: | ||
if has_robot_blocker(response.text): | ||
result["robot_friendly"] = False | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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\"')", | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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