コード例 #1
0
    def need_update(type, *ids):
        if not ids:
            return []
        ids = list(set(ids))

        if type == 'item':
            ids = [ids[i] for i, wc in enumerate(WC.contains(*ids)) if not wc]
            if not ids:
                return []

        thehash = LC.gethash(type)
        tsnow = time.mktime(time.gmtime())
        if len(ids) == 1:
            lastchecks = [thehash.hget(ids[0])]
        else:
            lastchecks = thehash.hmget(*ids)

        needs = []
        for i, lastcheck in enumerate(lastchecks):
            # if there's no lastcheck, or lastcheck happened some time ago
            # try call on_update with id, if succeeded, update lastcheck in redis
            if type == 'item':
                if lastcheck:
                    if str(lastcheck).find('.') > 0:
                        lastcheck = float(lastcheck)
                    #print "get:", bin(int(lastcheck)), len(bin(int(lastcheck))) - 2
                if debouncing.can_update(lastcheck):
                    needs.append(ids[i])
            else:
                if lastcheck is None or float(lastcheck) + 86400 * 7 < tsnow:
                    needs.append(ids[i])
        return needs
コード例 #2
0
ファイル: caches.py プロジェクト: mobishift2011/data007
    def need_update(type, *ids):
        if not ids:
            return []
        ids = list(set(ids))

        if type == 'item':
            ids = [ ids[i] for i, wc in enumerate(WC.contains(*ids)) if not wc ]
            if not ids:
                return []

        thehash = LC.gethash(type)
        tsnow = time.mktime(time.gmtime())
        if len(ids) == 1:
            lastchecks = [thehash.hget(ids[0])]
        else:
            lastchecks = thehash.hmget(*ids)

        needs = []
        for i, lastcheck in enumerate(lastchecks): 
            # if there's no lastcheck, or lastcheck happened some time ago
            # try call on_update with id, if succeeded, update lastcheck in redis
            if type == 'item':
                if lastcheck:
                    if str(lastcheck).find('.') > 0:
                        lastcheck = float(lastcheck)
                    #print "get:", bin(int(lastcheck)), len(bin(int(lastcheck))) - 2
                if debouncing.can_update(lastcheck):
                    needs.append(ids[i])
            else:
                if lastcheck is None or float(lastcheck) + 86400*7 < tsnow:
                    needs.append(ids[i])
        return needs
コード例 #3
0
 def unchange_days(self, num):
     for i in range(1, num+1):
         time.time = partial(later_time, i)
         if can_update(self.sbin):
             info = {'num_instock':self.instock}
             self.sbin = get_update_bin(self.sbin, info)
             print "{}  to__crawl".format(i)
         else:
             print "{}  deboucing".format(i)