lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -16,7 +16,7 @@ def clean_json_response(raw_response: str) -> Dict[str, Any]:
|
|||
"""
|
||||
end_index = raw_response.rfind("}")
|
||||
if end_index != -1:
|
||||
raw_response = raw_response[:end_index + 1]
|
||||
raw_response = raw_response[: end_index + 1]
|
||||
response: Dict[str, Any] = json.loads(raw_response)
|
||||
return response
|
||||
|
||||
|
@ -27,20 +27,21 @@ def request_test_now(test_url: str) -> str:
|
|||
"User-Agent": "bypasscensorship.org",
|
||||
"Content-Type": "application/json;charset=utf-8",
|
||||
"Pragma": "no-cache",
|
||||
"Cache-Control": "no-cache"
|
||||
"Cache-Control": "no-cache",
|
||||
}
|
||||
request_count = 0
|
||||
while request_count < 180:
|
||||
params = {
|
||||
"url": test_url,
|
||||
"timestamp": str(int(time.time())) # unix timestamp
|
||||
}
|
||||
response = requests.post(api_url, params=params, headers=headers, json={}, timeout=30)
|
||||
params = {"url": test_url, "timestamp": str(int(time.time()))} # unix timestamp
|
||||
response = requests.post(
|
||||
api_url, params=params, headers=headers, json={}, timeout=30
|
||||
)
|
||||
response_data = clean_json_response(response.text)
|
||||
print(f"Response: {response_data}")
|
||||
if "url_test_id" in response_data.get("d", {}):
|
||||
url_test_id: str = response_data["d"]["url_test_id"]
|
||||
logging.debug("Test result for %s has test result ID %s", test_url, url_test_id)
|
||||
logging.debug(
|
||||
"Test result for %s has test result ID %s", test_url, url_test_id
|
||||
)
|
||||
return url_test_id
|
||||
request_count += 1
|
||||
time.sleep(2)
|
||||
|
@ -52,13 +53,19 @@ def request_test_result(url_test_id: str) -> int:
|
|||
headers = {
|
||||
"User-Agent": "bypasscensorship.org",
|
||||
"Pragma": "no-cache",
|
||||
"Cache-Control": "no-cache"
|
||||
"Cache-Control": "no-cache",
|
||||
}
|
||||
response = requests.get(url, headers=headers, timeout=30)
|
||||
response_data = response.json()
|
||||
tests = response_data.get("d", [])
|
||||
non_zero_curl_exit_count: int = sum(1 for test in tests if test.get("curl_exit_value") != "0")
|
||||
logging.debug("Test result for %s has %s non-zero exit values", url_test_id, non_zero_curl_exit_count)
|
||||
non_zero_curl_exit_count: int = sum(
|
||||
1 for test in tests if test.get("curl_exit_value") != "0"
|
||||
)
|
||||
logging.debug(
|
||||
"Test result for %s has %s non-zero exit values",
|
||||
url_test_id,
|
||||
non_zero_curl_exit_count,
|
||||
)
|
||||
return non_zero_curl_exit_count
|
||||
|
||||
|
||||
|
@ -81,7 +88,7 @@ class BlockBlockyAutomation(BlockMirrorAutomation):
|
|||
Proxy.url.is_not(None),
|
||||
Proxy.deprecated.is_(None),
|
||||
Proxy.destroyed.is_(None),
|
||||
Proxy.pool_id != -1
|
||||
Proxy.pool_id != -1,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue