Skip to content

Commit 77317de

Browse files
committed
build: migrate to PEP 621-compatible pyproject.toml and restructure project
- Replaced setup.py and setup.cfg with pyproject.toml for a modern build system. Updated project structure to align with the src directory convention. Adjusted imports, examples, and documentation for the updated layout and dependency changes.
1 parent 24b1dc6 commit 77317de

36 files changed

Lines changed: 115 additions & 92 deletions

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# .editorconfig
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Usage examples
3333
#### ImageToText
3434

3535
```python
36-
from capmonster_python import ImageToTextTask
36+
from src.capmonster_python import ImageToTextTask
3737

3838
capmonster = ImageToTextTask("API_KEY")
3939
task_id = capmonster.create_task(image_path="img.png")
@@ -44,7 +44,7 @@ print(result.get("text"))
4444
#### Recaptcha v2
4545

4646
```python
47-
from capmonster_python import RecaptchaV2Task
47+
from src.capmonster_python import RecaptchaV2Task
4848

4949
capmonster = RecaptchaV2Task("API_KEY")
5050
task_id = capmonster.create_task("website_url", "website_key")
@@ -55,7 +55,7 @@ print(result.get("gRecaptchaResponse"))
5555
#### Recaptcha v2 enterprise
5656

5757
```python
58-
from capmonster_python import RecaptchaV2EnterpriseTask
58+
from src.capmonster_python import RecaptchaV2EnterpriseTask
5959

6060
capmonster = RecaptchaV2EnterpriseTask("API_KEY")
6161
task_id = capmonster.create_task("website_url", "website_key", {"s": "payload value"}, "api_domain")
@@ -66,7 +66,7 @@ print(result.get("gRecaptchaResponse"))
6666
#### GeeTest
6767

6868
```python
69-
from capmonster_python import GeeTestTask
69+
from src.capmonster_python import GeeTestTask
7070

7171
capmonster = GeeTestTask("API_KEY")
7272
task_id = capmonster.create_task("website_url", "gt", "challenge")
@@ -79,7 +79,7 @@ print(result.get("validate"))
7979
#### Report incorrect captchas
8080

8181
```python
82-
from capmonster_python import RecaptchaV2Task
82+
from src.capmonster_python import RecaptchaV2Task
8383

8484
capmonster = RecaptchaV2Task("API_KEY")
8585
task_id = capmonster.create_task("website_url", "website_key")

examples/funcaptcha_request.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import requests
21
import re
3-
from capmonster_python import FuncaptchaTask
2+
3+
import requests
4+
5+
from src.capmonster_python import FuncaptchaTask
46

57

68
class FuncaptchaRequest:
@@ -35,6 +37,7 @@ def submit_form(self):
3537

3638
if __name__ == "__main__":
3739
from os import environ
40+
3841
client_key = environ["API_KEY"]
3942
example_request = FuncaptchaRequest(client_key)
4043
assert example_request.expected in example_request.submit_form()

examples/funcaptcha_selenium.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import re
2+
from time import sleep
3+
24
from selenium import webdriver
3-
from selenium.webdriver.firefox.options import Options
45
from selenium.webdriver.common.by import By
6+
from selenium.webdriver.firefox.options import Options
57
from selenium.webdriver.firefox.service import Service
68
from webdriver_manager.firefox import GeckoDriverManager
7-
from capmonster_python import FuncaptchaTask
8-
from time import sleep
9+
10+
from src.capmonster_python import FuncaptchaTask
911

1012

1113
class FuncaptchaSelenium:
@@ -45,6 +47,7 @@ def submit_form(self):
4547

4648
if __name__ == "__main__":
4749
from os import environ
50+
4851
client_key = environ["API_KEY"]
4952
headless = environ["HEADLESS"]
5053
environ["WDM_LOG_LEVEL"] = "0"

examples/hcaptcha_request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
from bs4 import BeautifulSoup
3-
from capmonster_python import HCaptchaTask
3+
4+
from src.capmonster_python import HCaptchaTask
45

56

67
class HCaptchaRequest:
@@ -35,6 +36,7 @@ def submit_form(self):
3536

3637
if __name__ == "__main__":
3738
from os import environ
39+
3840
client_key = environ["API_KEY"]
3941
example_request = HCaptchaRequest(client_key)
4042
assert example_request.expected in example_request.submit_form()

examples/hcaptcha_selenium.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from time import sleep
2+
13
from selenium import webdriver
2-
from selenium.webdriver.firefox.options import Options
34
from selenium.webdriver.common.by import By
5+
from selenium.webdriver.firefox.options import Options
46
from selenium.webdriver.firefox.service import Service
57
from webdriver_manager.firefox import GeckoDriverManager
6-
from capmonster_python import HCaptchaTask
7-
from time import sleep
8+
9+
from src.capmonster_python import HCaptchaTask
810

911

1012
class HCaptchaSelenium:
@@ -43,6 +45,7 @@ def submit_form(self):
4345

4446
if __name__ == "__main__":
4547
from os import environ
48+
4649
client_key = environ["API_KEY"]
4750
headless = environ["HEADLESS"]
4851
environ["WDM_LOG_LEVEL"] = "0"

examples/imagetotext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from capmonster_python import ImageToTextTask
1+
from src.capmonster_python import ImageToTextTask
22

33

44
class TextNumericExample:
@@ -26,6 +26,7 @@ def solve_numeric(self):
2626

2727
if __name__ == "__main__":
2828
from os import environ
29+
2930
client_key = environ["API_KEY"]
3031
example_text_numeric = TextNumericExample(client_key)
3132
assert example_text_numeric.expected_1 in example_text_numeric.solve_text()

examples/recaptchav2_request.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import requests
22
from bs4 import BeautifulSoup
3-
from capmonster_python import RecaptchaV2Task
3+
4+
from src.capmonster_python import RecaptchaV2Task
45

56

67
class RecaptchaRequest:
78
def __init__(self, _client_key: str):
89
self.captcha = RecaptchaV2Task(_client_key)
910
self.s = requests.Session()
10-
self.s.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0"}
11+
self.s.headers = {
12+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0"}
1113
self.website_url = "https://google.com/recaptcha/api2/demo"
1214
self.expected = "Verification Success... Hooray!"
1315

@@ -33,6 +35,7 @@ def submit_form(self):
3335

3436
if __name__ == "__main__":
3537
from os import environ
38+
3639
client_key = environ["API_KEY"]
3740
example_request = RecaptchaRequest(client_key)
3841
assert example_request.expected in example_request.submit_form()

examples/recaptchav2_selenium.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from time import sleep
2+
13
from selenium import webdriver
24
from selenium.webdriver.common.by import By
35
from selenium.webdriver.firefox.options import Options
46
from selenium.webdriver.firefox.service import Service
57
from webdriver_manager.firefox import GeckoDriverManager
6-
from capmonster_python import RecaptchaV2Task
7-
from time import sleep
8+
9+
from src.capmonster_python import RecaptchaV2Task
810

911

1012
class RecaptchaV2Selenium:
@@ -41,6 +43,7 @@ def submit_form(self):
4143

4244
if __name__ == "__main__":
4345
from os import environ
46+
4447
client_key = environ["API_KEY"]
4548
headless = environ["HEADLESS"]
4649
environ["WDM_LOG_LEVEL"] = "0"

examples/turnstile_request.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import requests
21
from re import search
2+
3+
import requests
34
from bs4 import BeautifulSoup
4-
from capmonster_python import TurnstileTask
5+
6+
from src.capmonster_python import TurnstileTask
57

68

79
class TurnstileRequest:
810
def __init__(self, _client_key: str):
911
self.captcha = TurnstileTask(_client_key)
1012
self.s = requests.Session()
11-
self.s.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0"}
13+
self.s.headers = {
14+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0"}
1215
self.website_url = "http://tsmanaged.zlsupport.com"
1316
self.expected = 'Success!'
1417

1518
def _form_html(self):
1619
return self.s.get(self.website_url).text
1720

1821
def _site_token(self):
19-
site_key = search(r"sitekey: '(.+?)'", BeautifulSoup(self._form_html(), "html.parser").find_all("script")[1].text).group(1)
22+
site_key = search(r"sitekey: '(.+?)'",
23+
BeautifulSoup(self._form_html(), "html.parser").find_all("script")[1].text).group(1)
2024
print("# Site key found: {}".format(site_key))
2125
task_id = self.captcha.create_task(website_url=self.website_url, website_key=site_key)
2226
print("# Task created successfully")
@@ -31,14 +35,14 @@ def submit_form(self):
3135
'password': 'test',
3236
'token': result,
3337
}
34-
response = self.s.post(self.website_url+'/send', data=data, headers=self.s.headers, verify=False)
38+
response = self.s.post(self.website_url + '/send', data=data, headers=self.s.headers, verify=False)
3539
return BeautifulSoup(response.text, "html.parser").title.string
3640

3741

3842
if __name__ == "__main__":
3943
from os import environ
44+
4045
client_key = environ["API_KEY"]
4146
example_request = TurnstileRequest(client_key)
4247
assert example_request.expected in example_request.submit_form()
4348
print("# Submit succeed, test is OK")
44-

0 commit comments

Comments
 (0)