|
| 1 | +import re |
| 2 | + |
| 3 | +from curl_cffi.requests.exceptions import RequestException |
| 4 | + |
| 5 | +from user_scanner.core.impersonate import impersonate_request_async |
| 6 | +from user_scanner.core.result import Result |
| 7 | + |
| 8 | +SHOW_URL = "https://www.quora.com" |
| 9 | +QUERY_NAME = "SignupEmailForm_validateEmail_Query" |
| 10 | +QUERY_HASH = "1db80096407be846d5581fe1b42b12fd05e0b40a5d3095ed40a0b4bd28f49fe7" |
| 11 | + |
| 12 | + |
| 13 | +async def validate_quora(email: str) -> Result: |
| 14 | + """Quiet signup validation probe. It sends no email.""" |
| 15 | + try: |
| 16 | + page = await impersonate_request_async(SHOW_URL, allow_redirects=True) |
| 17 | + formkey = re.search(r'"formkey":\s*"([a-f0-9]+)"', page.text) |
| 18 | + if page.status_code != 200 or not formkey: |
| 19 | + return Result.error( |
| 20 | + f"Could not load Quora login page: {page.status_code}", |
| 21 | + url=SHOW_URL, |
| 22 | + ) |
| 23 | + |
| 24 | + response = await impersonate_request_async( |
| 25 | + f"{SHOW_URL}/graphql/gql_para_POST", |
| 26 | + "POST", |
| 27 | + params={"q": QUERY_NAME}, |
| 28 | + headers={"quora-formkey": formkey.group(1)}, |
| 29 | + json={ |
| 30 | + "queryName": QUERY_NAME, |
| 31 | + "variables": {"email": email}, |
| 32 | + "extensions": {"hash": QUERY_HASH}, |
| 33 | + }, |
| 34 | + ) |
| 35 | + if response.status_code != 200: |
| 36 | + return Result.error( |
| 37 | + f"Unexpected Quora response: {response.status_code}", |
| 38 | + url=SHOW_URL, |
| 39 | + ) |
| 40 | + |
| 41 | + state = (response.json().get("data") or {}).get("validateEmail") |
| 42 | + if state in {"IN_USE", "NOT_CONFIRMED"}: |
| 43 | + confirmed = state == "IN_USE" |
| 44 | + return Result.taken(url=SHOW_URL, extra={"email_confirmed": confirmed}) |
| 45 | + if state == "OK": |
| 46 | + return Result.available(url=SHOW_URL) |
| 47 | + return Result.error(f"Unexpected Quora signup state: {state}", url=SHOW_URL) |
| 48 | + except (RequestException, ValueError, AttributeError) as exc: |
| 49 | + return Result.error(exc, url=SHOW_URL) |
0 commit comments