Exemple #1
0
    def process_response(self, parse_response=True):
        """Post processing of the response"""

        self.response = Response(self.response,
                                 verb=self.verb,
                                 list_nodes=self._list_nodes,
                                 datetime_nodes=self.datetime_nodes,
                                 parse_response=parse_response)

        # set for backward compatibility
        self._response_content = self.response.content
        if self.response.status_code != 200:
            self._response_error = self.response.reason
            raise ConnectionError(self.self._response_error, self.response)
Exemple #2
0
    def error_check(self):
        estr = self.error()

        if estr and self.config.get('errors', True):
            log.error(estr)
            raise ConnectionError(estr, self.response)
Exemple #3
0
    def get_seller_list(self, cr, uid, user, context=None):
        last_updated = user.last_updated
        if last_updated:
            now_time = datetime.now()
            last_updated = datetime.strptime(
                last_updated, tools.DEFAULT_SERVER_DATETIME_FORMAT)
            delta = (now_time - last_updated).days
            if delta < 7:
                return True

        cr.execute(
            'delete from ebay_seller_list \
                        where user_id=%s', (user.id, ))

        now = datetime.now()
        end_time_from = now.isoformat()
        end_time_to = (now + timedelta(30)).isoformat()
        entries_per_page = 160
        page_number = 1

        call_param = dict(end_time_from=end_time_from,
                          end_time_to=end_time_to,
                          entries_per_page=entries_per_page,
                          page_number=page_number)

        reply = self.get_seller_list_call(cr,
                                          uid,
                                          user,
                                          call_param,
                                          context=context).response.reply
        total_number_of_pages = int(reply.PaginationResult.TotalNumberOfPages)

        if total_number_of_pages == 0:
            return True

        monthly_sales, monthly_sales_volume = self.create_items(
            cr, uid, user, reply.ItemArray.Item, context=context)

        page_number = 2
        total_number_of_pages += 1
        while page_number < total_number_of_pages:
            parallel = Parallel()
            multiple_threads = 0
            apis = list()
            while page_number < total_number_of_pages and multiple_threads < 5:
                call_param = dict(end_time_from=end_time_from,
                                  end_time_to=end_time_to,
                                  entries_per_page=entries_per_page,
                                  page_number=page_number)
                apis.append(
                    self.get_seller_list_call(cr,
                                              uid,
                                              user,
                                              call_param,
                                              parallel=parallel,
                                              context=context))
                page_number += 1
                multiple_threads += 1

            parallel.wait(120)

            for api in apis:
                reply = api.response.reply
                if reply.Ack in ('Success', 'Warning'):
                    _monthly_sales, _monthly_sales_volume = self.create_items(
                        cr, uid, user, reply.ItemArray.Item, context=context)
                    monthly_sales += _monthly_sales
                    monthly_sales_volume += _monthly_sales_volume
                else:
                    raise ConnectionError(api.error())

        return user.write(
            dict(last_updated=fields.datetime.now(),
                 monthly_sales=monthly_sales,
                 monthly_sales_volume=monthly_sales_volume))