Ejemplo n.º 1
0
def index():
    item_reader = ItemReader()
    indexer = ItemIndexer(_api_client, _index_name)
    
    curr_millis = _start_millis
    while True:
        try:
            snapshot_resp = fetch('https://api.mercadolibre.com/items/snapshot/%s' % curr_millis)
            json_str = snapshot_resp.content
            json_obj = anyjson.deserialize(json_str)
            
            for item_id in json_obj:
                try:
                    item = item_reader.get_item(item_id)
                    item.indexed = False
                    item.save()
                    indexer.index(item)
                    indexer.update_categories(item)
                    indexer.update_variables(item)
                    item.indexed = True
                    item.save()
                    print 'item indexed %s' % item_id
                
                except Exception, e:
                    print e

            curr_millis += 1000
        except Exception, e:
            print e
Ejemplo n.º 2
0
class ItemIndexerThread:

    def __init__(self, items_queue, api_client):
        self.__items_queue = items_queue
        self.__item_indexer = ItemIndexer(api_client, _index_name) 

    def index(self):
        global items_indexed
        while True:
            item = self.__items_queue.get()
            try:
                self.__item_indexer.index(item)
                items_indexed += 1
            except HTTPError, e:
                print e