예제 #1
0
def get_data(user, length=4):

    cache_key = 'user_%s:%s' % (length, user.replace(" ", "+"))

    data = None  #cache.get(cache_key)
    while data == "locked":
        time.sleep(0.01)

    if not data:

        #cache.set(cache_key, "locked", 5)
        try:
            weeks = list(fetcher.weeks(user))
        except:
            import traceback
            try:
                errfile.write(traceback.format_exc())
                errfile.flush()
            except:
                pass
            return None, None
        threads = [
            ThreadedWeek(user, start, end) for start, end in weeks[-length:]
        ]
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()
        data = ([thread.data for thread in threads], weeks[-length:])

    #cache.set(cache_key, data, 30)

    return data
예제 #2
0
파일: slice.py 프로젝트: 0x414c/lastgraph
def get_data(user, length=4):
    
    cache_key = 'user_%s:%s' % (length, user.replace(" ","+"))
    
    data = None #cache.get(cache_key)
    while data == "locked":
        time.sleep(0.01)
    
    if not data:
        
        #cache.set(cache_key, "locked", 5)
        try:
            weeks = list(fetcher.weeks(user))
        except:
            import traceback
            try:
                errfile.write(traceback.format_exc())
                errfile.flush()
            except:
                pass
            return None, None
        threads = [ThreadedWeek(user, start, end) for start, end in weeks[-length:]]
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()
        data = ([thread.data for thread in threads], weeks[-length:])
    
    #cache.set(cache_key, data, 30)
    
    return data
예제 #3
0
def user_ready(username):
    if username.endswith(".php"):
        return False

    uh = UserHistory(username)

    # First, check to see if the file is fresh
    uh.load_if_possible()
    if uh.data_age() < settings.HISTORY_TTL:
        return uh.num_weeks()

    # Then, do a quick weeklist fetch to compare
    try:
        weeks = list(fetcher.weeks(username))
    except AssertionError:  # They probably don't exist
        return None

    present = True
    for start, end in weeks:
        if not uh.has_week(start):
            present = False
            break

    # If all weeks were present, update the timestamp
    if present:
        uh.set_timestamp()
        uh.save_default()
        return len(weeks)
    else:
        return False
예제 #4
0
파일: views.py 프로젝트: 0x414c/lastgraph
def user_ready(username):
    if username.endswith(".php"):
        return False
    
    uh = UserHistory(username)
    
    # First, check to see if the file is fresh
    uh.load_if_possible()
    if uh.data_age() < settings.HISTORY_TTL:
        return uh.num_weeks()
    
    # Then, do a quick weeklist fetch to compare
    try:
        weeks = list(fetcher.weeks(username))
    except AssertionError:  # They probably don't exist
        return None
    
    present = True
    for start, end in weeks:
        if not uh.has_week(start):
            present = False
            break
    
    # If all weeks were present, update the timestamp
    if present:
        uh.set_timestamp()
        uh.save_default()
        return len(weeks)
    else:
        return False