(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs)
return data if is_detail_result else data['target']
https://fanyi.caiyunapp.com
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param professional_field: str, default None, choose from ("medicine","law","machinery")
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or dict
https://fanyi.caiyunapp.com
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param professional_field: str, default None, choose from ("medicine","law","machinery")
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or dict
https : // fanyi . caiyunapp . com : param query_text : str must . : param from_language : str default auto . : param to_language : str default en . : param ** kwargs : : param professional_field : str default None choose from ( medicine law machinery ) : param if_ignore_limit_of_length : boolean default False . : param is_detail_result : boolean default False . : param timeout : float default None . : param proxies : dict default None . : param sleep_seconds : float default random . random () . : return : str or dict
def caiyun_api(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs) -> Union[str, dict]:
        """
        https://fanyi.caiyunapp.com
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param professional_field: str, default None, choose from ("medicine","law","machinery")
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or dict
        """
        use_domain = kwargs.get('professional_field', None)
        if use_domain:
            assert use_domain in ("medicine", "law", "machinery")
        is_detail_result = kwargs.get('is_detail_result', False)
        timeout = kwargs.get('timeout', None)
        proxies = kwargs.get('proxies', None)
        sleep_seconds = kwargs.get('sleep_seconds', random.random())
        if_ignore_limit_of_length = kwargs.get('if_ignore_limit_of_length', False)
        query_text = self.check_query_text(query_text, if_ignore_limit_of_length)

        with requests.Session() as ss:
            host_html = ss.get(self.host_url, headers=self.host_headers, timeout=timeout, proxies=proxies).text
            if not self.get_tk_url:
                self.get_tk_url = self.host_url + re.compile(self.get_tk_pattern).search(host_html).group()
            if not self.language_map:
                self.language_map = self.get_language_map(ss, timeout, proxies)

            from_language, to_language = self.check_language(from_language, to_language, self.language_map, output_zh=self.output_zh)
            self.tk = self.get_tk(ss, timeout, proxies)
            self.api_headers.update({
                "app-name": "xy",
                "device-id": "",
                "os-type": "web",
                "os-version": "",
                "version": "1.8.0",
                "X-Authorization": self.tk,
            })
            self.jwt = self.get_jwt(self.browser_id, self.api_headers, ss, timeout, proxies)
            self.api_headers.update({"T-Authorization": self.jwt})
            form_data = {
                "browser_id": self.browser_id,
                "cached": "true",
                "dict": "true",
                "media": "text",
                "os_type": "web",
                "replaced": "true",
                "request_id": "web_fanyi",
                "source": query_text,
                "trans_type": f"{from_language}2{to_language}",
            }
            if from_language == 'auto':
                form_data.update({'detect': 'true'})
            if use_domain:
                form_data.update({"dict_name": use_domain, "use_common_dict": "true"})
            _ = ss.options(self.api_url, headers=self.host_headers, timeout=timeout, proxies=proxies)
            r = ss.post(self.api_url, headers=self.api_headers, json=form_data, timeout=timeout, proxies=proxies)
            r.raise_for_status()
            data = r.json()
        time.sleep(sleep_seconds)
        self.query_count += 1
        self.api_headers.pop('T-Authorization')
        data['target'] = self.decrypt(data['target'])
        return data if is_detail_result else data['target']
def caiyun_api ( self , query_text : str , from_language : str = 'auto' , to_language : str = 'en' , * * kwargs ) -> Union [ str , dict ] : use_domain = kwargs . get ( 'professional_field' , None ) if use_domain : assert use_domain in ( "medicine" , "law" , "machinery" ) is_detail_result = kwargs . get ( 'is_detail_result' , False ) timeout = kwargs . get ( 'timeout' , None ) proxies = kwargs . get ( 'proxies' , None ) sleep_seconds = kwargs . get ( 'sleep_seconds' , random . random ( ) ) if_ignore_limit_of_length = kwargs . get ( 'if_ignore_limit_of_length' , False ) query_text = self . check_query_text ( query_text , if_ignore_limit_of_length ) with requests . Session ( ) as ss : host_html = ss . get ( self . host_url , headers = self . host_headers , timeout = timeout , proxies = proxies ) . text if not self . get_tk_url : self . get_tk_url = self . host_url + re . compile ( self . get_tk_pattern ) . search ( host_html ) . group ( ) if not self . language_map : self . language_map = self . get_language_map ( ss , timeout , proxies ) from_language , to_language = self . check_language ( from_language , to_language , self . language_map , output_zh = self . output_zh ) self . tk = self . get_tk ( ss , timeout , proxies ) self . api_headers . update ( { "app-name" : "xy" , "device-id" : "" , "os-type" : "web" , "os-version" : "" , "version" : "1.8.0" , "X-Authorization" : self . tk , } ) self . jwt = self . get_jwt ( self . browser_id , self . api_headers , ss , timeout , proxies ) self . api_headers . update ( { "T-Authorization" : self . jwt } ) form_data = { "browser_id" : self . browser_id , "cached" : "true" , "dict" : "true" , "media" : "text" , "os_type" : "web" , "replaced" : "true" , "request_id" : "web_fanyi" , "source" : query_text , "trans_type" : f"{from_language}2{to_language}" , } if from_language == 'auto' : form_data . update ( { 'detect' : 'true' } ) if use_domain : form_data . update ( { "dict_name" : use_domain , "use_common_dict" : "true" } ) _ = ss . options ( self . api_url , headers = self . host_headers , timeout = timeout , proxies = proxies ) r = ss . post ( self . api_url , headers = self . api_headers , json = form_data , timeout = timeout , proxies = proxies ) r . raise_for_status ( ) data = r . json ( ) time . sleep ( sleep_seconds ) self . query_count += 1 self . api_headers . pop ( 'T-Authorization' ) data [ 'target' ] = self . decrypt ( data [ 'target' ] ) return data if is_detail_result else data [ 'target' ]