예제 #1
0
def run(opts):

    try:
        p = Parallel()
        apis = []

        api1 = finding(parallel=p, debug=opts.debug, appid=opts.appid, config_file=opts.yaml)
        api1.execute('findItemsAdvanced', {'keywords': 'python'})
        apis.append(api1)

        api4 = html(parallel=p)
        api4.execute('http://www.ebay.com/sch/i.html?_nkw=Shirt&_rss=1')
        apis.append(api4)

        api2 = finding(parallel=p, debug=opts.debug, appid=opts.appid, config_file=opts.yaml)
        api2.execute('findItemsAdvanced', {'keywords': 'perl'})
        apis.append(api2)

        api3 = finding(parallel=p, debug=opts.debug, appid=opts.appid, config_file=opts.yaml)
        api3.execute('findItemsAdvanced', {'keywords': 'php'})
        apis.append(api3)

        p.wait()

        if p.error():
            print(p.error())

        for api in apis:
            dump(api)

    except ConnectionError as e:
        print(e)
        print(e.response.dict())
예제 #2
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))
예제 #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
     ))