Esempio n. 1
0
 def __init__(self):
     self.timeout = config.getfloat("CONNECTION", "Timeout")
     self.cse_id = config.get("CONNECTION", "GoogleCseId")
     api_key = config.get("CONNECTION", "GoogleApiKey")
     self.search_service = googleapiclient.discovery.build("customsearch", "v1", developerKey=api_key)
     self.session = aiohttp.ClientSession(headers=Searcher.HEADERS)
     self.logger = logging.getLogger(__name__)
Esempio n. 2
0
    def __init__(self):
        self.timeout = config.getfloat('CONNECTION', 'Timeout')
        self.search_service = config.get('SEARCH', 'Service')

        bing_api_key = config.get('SEARCH', 'BingApiKey')
        self.bing_headers = {'Ocp-Apim-Subscription-Key': bing_api_key}

        self.google_cse_id = config.get('SEARCH', 'GoogleCseId')
        self.google_api_key = config.get('SEARCH', 'GoogleApiKey')

        # don't use default headers for Bing search so searcher tests
        # can run get_bing_links/get_google_links on its own
        # without depending on search_service being set correctly
        self.search_session = aiohttp.ClientSession()

        if self.search_service == 'Bing':
            self.search_func = self.get_bing_links
        elif self.search_service == 'Google':
            self.search_func = self.get_google_links
        else:
            raise InvalidSearchServiceError(
                f'Search service type {self.search_service} was not recognized.'
            )

        client_timeout = aiohttp.ClientTimeout(total=self.timeout)
        self.fetch_session = aiohttp.ClientSession(headers=Searcher.HEADERS,
                                                   timeout=client_timeout)
        self.logger = logging.getLogger(__name__)
Esempio n. 3
0
    def __init__(self):
        self.timeout = config.getfloat('CONNECTION', 'Timeout')
        self.search_service = config.get('SEARCH', 'Service')

        bing_api_key = config.get('SEARCH', 'BingApiKey')
        self.bing_headers = {'Ocp-Apim-Subscription-Key': bing_api_key}

        self.google_cse_id = config.get('SEARCH', 'GoogleCseId')
        google_api_key = config.get('SEARCH', 'GoogleApiKey')
        self.google_service = googleapiclient.discovery.build(
            'customsearch', 'v1', developerKey=google_api_key)

        if self.search_service == 'Bing':
            self.search_func = self.get_bing_links
        elif self.search_service == 'Google':
            self.search_func = self.get_google_links
        else:
            raise InvalidSearchServiceError(
                f'Search service type {self.search_service} was not recognized.'
            )

        client_timeout = aiohttp.ClientTimeout(total=self.timeout)
        self.session = aiohttp.ClientSession(headers=Searcher.HEADERS,
                                             timeout=client_timeout)
        self.logger = logging.getLogger(__name__)
    def __init__(self):
        self.timeout = config.getfloat("CONNECTION", "Timeout")
        self.search_service = config.get("SEARCH", "Service")

        bing_api_key = config.get("SEARCH", "BingApiKey")
        self.bing_headers = {"Ocp-Apim-Subscription-Key": bing_api_key}

        self.google_cse_id = config.get("SEARCH", "GoogleCseId")
        google_api_key = config.get("SEARCH", "GoogleApiKey")
        self.google_service = googleapiclient.discovery.build("customsearch", "v1", developerKey=google_api_key)

        if self.search_service == "Bing":
            self.search_func = self.get_bing_links
        elif self.search_service == "Google":
            self.search_func = self.get_google_links
        else:
            raise InvalidSearchServiceError(f"Search service type {self.search_service} was not recognized.")

        self.session = aiohttp.ClientSession(headers=Searcher.HEADERS)
        self.logger = logging.getLogger(__name__)
Esempio n. 5
0
def main():
    signal.signal(signal.SIGINT, mark_terminate)
    signal.signal(signal.SIGTERM, mark_terminate)

    bearer = config.get('CONNECTION', 'BEARER')
    headers = {
        'User-Agent': 'Android/1.40.0',
        'x-hq-client': 'Android/1.40.0',
        'x-hq-country': 'US',
        'x-hq-lang': 'en',
        'x-hq-timezone': 'America/New_York',
        'Authorization': f'Bearer {bearer}',
        # 'Connection': 'Upgrade'
    }
    uri = 'wss://ws.prod.hype.space/ws/52637?universal'

    loop = asyncio.get_event_loop()
    msgs = loop.run_until_complete(ws_connect(uri, headers))
    print(pickle.dumps(msgs))

    with open(next_fname('msgs{}.pickle'), 'wb') as out:
        pickle.dump(msgs, out)