Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ name: Python package
on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- uses: j178/prek-action@v1

test:
runs-on: ubuntu-latest

Expand Down
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.10
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
additional_dependencies: [types-requests>=2.31]
files: ^python_anticaptcha/
pass_filenames: false
args: [python_anticaptcha]
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CHROMEDRIVER_VERSION=99.0.4844.17
CHROMEDRIVER_DIR=${PWD}/chromedriver

.PHONY: lint fmt build docs install test test_e2e chromedriver
.PHONY: lint fmt typecheck build docs install test test_e2e chromedriver

build:
python -m build
Expand Down Expand Up @@ -34,11 +34,15 @@ clean:
rm -r build chromedriver

lint:
docker run --rm -v /$$(pwd):/apps alpine/flake8 ./
docker run --rm -v /$$(pwd):/data cytopia/black --check ./
ruff check .
ruff format --check .

fmt:
docker run --rm -v /$$(pwd):/data cytopia/black ./
ruff check --fix .
ruff format .

typecheck:
mypy python_anticaptcha

docs:
sphinx-build -W docs /dev/shm/sphinx
23 changes: 10 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -20,13 +19,13 @@

# -- Project information -----------------------------------------------------

project = u"python-anticaptcha"
copyright = u"2018-2026, Adam Dobrawy"
author = u"Adam Dobrawy"
project = "python-anticaptcha"
copyright = "2018-2026, Adam Dobrawy"
author = "Adam Dobrawy"

# Version is managed by setuptools-scm; leave empty for Sphinx
version = u""
release = u""
version = ""
release = ""


# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -69,7 +68,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = [u"_build", "Thumbs.db", ".DS_Store"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
Expand Down Expand Up @@ -143,8 +142,8 @@
(
master_doc,
"python-anticaptcha.tex",
u"python-anticaptcha Documentation",
u"Adam Dobrawy",
"python-anticaptcha Documentation",
"Adam Dobrawy",
"manual",
),
]
Expand All @@ -154,9 +153,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, "python-anticaptcha", u"python-anticaptcha Documentation", [author], 1)
]
man_pages = [(master_doc, "python-anticaptcha", "python-anticaptcha Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -168,7 +165,7 @@
(
master_doc,
"python-anticaptcha",
u"python-anticaptcha Documentation",
"python-anticaptcha Documentation",
author,
"python-anticaptcha",
"One line description of project.",
Expand Down
5 changes: 2 additions & 3 deletions examples/antigate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import json
from os import environ
from re import TEMPLATE

from python_anticaptcha import AnticaptchaClient
from python_anticaptcha.tasks import AntiGateTask, AntiGateTaskProxyless
import json
from python_anticaptcha.tasks import AntiGateTaskProxyless

api_key = environ["KEY"]

Expand Down
3 changes: 2 additions & 1 deletion examples/app_stat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from os import environ
from pprint import pprint
from python_anticaptcha import AnticaptchaClient, ImageToTextTask
from sys import argv

from python_anticaptcha import AnticaptchaClient

api_key = environ["KEY"]

soft_id = argv[1]
Expand Down
4 changes: 2 additions & 2 deletions examples/balance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os import environ
from pprint import pprint
from python_anticaptcha import AnticaptchaClient, ImageToTextTask
from sys import argv

from python_anticaptcha import AnticaptchaClient

api_key = environ["KEY"]

Expand Down
9 changes: 5 additions & 4 deletions examples/funcaptcha_request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from six.moves.urllib import parse
import requests
from os import environ
import re
from os import environ

import requests
from six.moves.urllib import parse

from python_anticaptcha import AnticaptchaClient, FunCaptchaTask

Expand Down Expand Up @@ -50,7 +51,7 @@ def get_token(form_html):

def form_submit(token):
return requests.post(
url="{}/verify".format(url),
url=f"{url}/verify",
data={"name": "xx", "fc-token": token},
proxies={
"http": proxy_url,
Expand Down
11 changes: 4 additions & 7 deletions examples/funcaptcha_selenium.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from six.moves.urllib.parse import quote
from six.moves.urllib import parse

import requests
from os import environ
import re
from os import environ
from random import choice

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from six.moves.urllib import parse
from six.moves.urllib.parse import quote

from python_anticaptcha import AnticaptchaClient, FunCaptchaTask

Expand Down
15 changes: 8 additions & 7 deletions examples/funcaptcha_selenium_callback.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import gzip
import os
import re
import time
from six.moves.urllib.parse import quote
import os
from os import environ
import gzip

from python_anticaptcha import AnticaptchaClient, FunCaptchaProxylessTask
from selenium.webdriver.common.by import By
from six.moves.urllib.parse import quote

from python_anticaptcha import AnticaptchaClient, FunCaptchaProxylessTask

api_key = environ["KEY"]
site_key_pattern = 'public_key: "(.+?)",'
Expand Down Expand Up @@ -47,7 +48,7 @@ def form_submit(driver, token):
)
time.sleep(1)
# as example call callback - not required in that example
driver.execute_script("ArkoseEnforcement.funcaptchaCallback[0]('{}')".format(token))
driver.execute_script(f"ArkoseEnforcement.funcaptchaCallback[0]('{token}')")
driver.find_element(By.ID, "submit-btn").click()
time.sleep(1)

Expand All @@ -62,9 +63,9 @@ def get_sitekey(driver):
def custom(req, req_body, res, res_body):
if not req.path:
return
if not "arkoselabs" in req.path:
if "arkoselabs" not in req.path:
return
if not res.headers.get("Content-Type", None) in [
if res.headers.get("Content-Type", None) not in [
"text/javascript",
"application/javascript",
]:
Expand Down
3 changes: 2 additions & 1 deletion examples/hcaptcha_request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import re
import requests
from os import environ

import requests

from python_anticaptcha import AnticaptchaClient, HCaptchaTaskProxyless

api_key = environ["KEY"]
Expand Down
6 changes: 3 additions & 3 deletions examples/hcaptcha_request_proxy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from six.moves.urllib import parse

import re
import requests
from os import environ

import requests
from six.moves.urllib import parse

from python_anticaptcha import AnticaptchaClient, HCaptchaTask

api_key = environ["KEY"]
Expand Down
8 changes: 5 additions & 3 deletions examples/recaptcha3_request.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import re
import requests
from os import environ

import requests
from six.moves.urllib_parse import urljoin

from python_anticaptcha import AnticaptchaClient, RecaptchaV3TaskProxyless

api_key = environ["KEY"]
site_key_pattern = "grecaptcha.execute\('(.+?)'"
action_name_pattern = "\{action: '(.+?)'\}"
site_key_pattern = r"grecaptcha.execute\('(.+?)'"
action_name_pattern = r"\{action: '(.+?)'\}"
url = "https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php"
client = AnticaptchaClient(api_key)
session = requests.Session()
Expand Down
3 changes: 2 additions & 1 deletion examples/recaptcha_request.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import re
import requests
from os import environ

import requests

from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask

api_key = environ["KEY"]
Expand Down
8 changes: 3 additions & 5 deletions examples/recaptcha_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

api_key = environ["KEY"]
invisible_captcha = True
url = "https://www.google.com/recaptcha/api2/demo?invisible={}".format(
str(invisible_captcha)
)
url = f"https://www.google.com/recaptcha/api2/demo?invisible={str(invisible_captcha)}"
EXPECTED_RESULT = "Verification Success... Hooray!"
client = AnticaptchaClient(api_key)

Expand All @@ -33,9 +31,9 @@ def process(driver):

def form_submit(driver, token):
driver.execute_script(
"document.getElementById('g-recaptcha-response').innerHTML='{}';".format(token)
f"document.getElementById('g-recaptcha-response').innerHTML='{token}';"
)
driver.execute_script("onSuccess('{}')".format(token))
driver.execute_script(f"onSuccess('{token}')")
time.sleep(1)


Expand Down
10 changes: 5 additions & 5 deletions examples/recaptcha_selenium_callback.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import gzip
import os
import re
import time
import os
from os import environ
import gzip

from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask

Expand Down Expand Up @@ -37,9 +37,9 @@ def process(driver):

def form_submit(driver, token):
driver.execute_script(
"document.getElementById('g-recaptcha-response').innerHTML='{}';".format(token)
f"document.getElementById('g-recaptcha-response').innerHTML='{token}';"
)
driver.execute_script("grecaptcha.recaptchaCallback[0]('{}')".format(token))
driver.execute_script(f"grecaptcha.recaptchaCallback[0]('{token}')")
time.sleep(1)


Expand All @@ -51,7 +51,7 @@ def get_sitekey(driver):
from seleniumwire import webdriver # Import from seleniumwire

def custom(req, req_body, res, res_body):
if not req.path or not "recaptcha" in req.path:
if not req.path or "recaptcha" not in req.path:
return
if not res.headers.get("Content-Type", None) == "text/javascript":
return
Expand Down
3 changes: 2 additions & 1 deletion examples/remote_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
from os import environ

import requests

from python_anticaptcha import AnticaptchaClient, ImageToTextTask

api_key = environ["KEY"]
Expand Down
2 changes: 1 addition & 1 deletion examples/text_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

api_key = environ["KEY"]
DIR = os.path.dirname(os.path.abspath(__file__))
IMAGE = "{}/captcha_ms.jpeg".format(DIR)
IMAGE = f"{DIR}/captcha_ms.jpeg"
EXPECTED_RESULT = "56nn2"


Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ python_anticaptcha = ["py.typed"]
[tool.setuptools-scm]
fallback_version = "0.0.0"

[tool.ruff]
target-version = "py39"
line-length = 120
extend-exclude = ["examples"]

[tool.ruff.lint]
select = ["E", "F", "W", "I", "UP", "B", "SIM"]

[tool.mypy]
python_version = "3.9"
warn_unused_configs = true
disallow_untyped_defs = true
no_implicit_optional = true

[[tool.mypy.overrides]]
module = "requests.*"
ignore_missing_imports = true

[tool.pytest.ini_options]
testpaths = ["tests"]
markers = [
Expand Down
Loading
Loading