コード例 #1
0
 async def _async_get(session, url, item, headers={}, cookies={}, params={}, printer=None, iteration=None):
     """
     Execute http get requests using an aiohttp session.
     :param session: Aiohttp session
     :param url: Url for http request
     :param headers: Headers for http request
     :param cookies: Cookies for http request
     :param printer: (print_func, total, task) for printing
     :param iteration: List with single integer for counting current iteration
     :return: Custom response object
     """
     async with session.get(url, headers=headers, cookies=cookies, params=params) as response:
         if printer is not None and iteration is not None:
             iteration[0] += 1
             print_func, total, task = printer
             print_func(iteration[0], total, task)
         image = await response.read()
         try:
             json = await response.json()
         except Exception:
             json = None
         try:
             text = await response.text()
         except Exception:
             text = None
         return item, req.Response(response, None, None, json, text, read=image)
コード例 #2
0
 async def _async_put_json(session, url, payload, headers={}, cookies={}, params={}, printer=None, iteration=None):
     """
     Execute http put requests using an aiohttp session.
     :param session: Aiohttp session
     :param url: Url for http request
     :param payload: Json data for request
     :param headers: Headers for http request
     :param cookies: Cookies for http request
     :param printer: (print_func, total, task) for printing
     :param iteration: List with single integer for counting current iteration
     :return: Custom response object
     """
     async with session.put(url, headers=headers, cookies=cookies, json=payload, params=params) as response:
         if printer is not None and iteration is not None:
             iteration[0] += 1
             print_func, total, task = printer
             print_func(iteration[0], total, task)
         heads1, json1, body1 = None, None, None
         return req.Response(response, payload, heads1, json1, body1)
コード例 #3
0
ファイル: model.py プロジェクト: TooMuch4U/pisspricer-scraper
 async def _async_get_item_page(session,
                                url,
                                item,
                                cookies,
                                params,
                                printer=None):
     """
     Gets Item page using session
     :param session: Session for request
     :param url: Url for http get request
     :param item: Dict item object to get returned with response
     :param cookies: Cookies for http request
     :param printer: (print_func, total, task, iteration) tuple
     :param params: Params for http request
     :return: (item, res) tuple, custom Response object
     """
     async with session.get(url, cookies=cookies, params=params) as res:
         text = await res.text()
         new_res = req.Response(res, None, {}, None, text)
         if printer is not None:
             print_func, total, task, iteration = printer
             print_func(iteration[0], total, task)
             iteration[0] += 1
         return item, new_res