File size: 1,019 Bytes
c0e9d84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Union, Optional
import httpx

from .dicts import ANSWERS, HEADERS

def request_handler(url: str, method: str, data: Optional[dict] = None) -> httpx.Response:
    if method == 'GET':
        return httpx.get(url, headers=HEADERS, timeout=30.0)
    elif method == 'POST':
        return httpx.post(url, headers=HEADERS, data=data, timeout=30.0)
    else:
        raise ValueError(f"Unsupported HTTP method: {method}")

async def async_request_handler(url: str, method: str, data: Optional[dict] = None) -> httpx.Response:
    async with httpx.AsyncClient() as client:
        if method == 'GET':
            return await client.get(url, headers=HEADERS, timeout=30.0)
        elif method == 'POST':
            return await client.post(url, headers=HEADERS, data=data, timeout=30.0)
        else:
            raise ValueError(f"Unsupported HTTP method: {method}")

def get_answer_id(ans):
    for key, values in ANSWERS.items():
        if ans.lower() in values:
            return key
    return None