def loop():
    db = get_db()
    api = ImgurApi()
    
    while True:
        configs = load_config()
        info("New loop with credits: %s" % api.credits)
        
        db.update_matviews()
        
        for config in configs:
            start, max_iter = config.get('chunks', [0, config['end']])
            if start == config['end']: start = 0
            nconfig = dict(config.items())
            del nconfig['chunks']
            end = min(config['end'], start + max_iter)
            nconfig['start'] = start
            nconfig['end'] = end
            
            info("Fetching %s (sort: %s) of %s %i - %i." % (nconfig['section'], nconfig['sort'], nconfig['window'], nconfig['start'], nconfig['end']))
            o_count = - db.get_post_count()
            _iter = api.iter_galleries(delay=6, **nconfig)
            db._cacher(_iter, db.upsert_post, insert_images=True, commit_after=50)    
            o_count += db.get_post_count()
            info("Found %i new posts." % o_count)
            
            if 'chunks' in config:
                config['chunks'][0] = end
                save_config(configs)
                
        db.update_matviews()
        time.sleep(60*20)
Beispiel #2
0
def render_user_info(username=None, userid=None):
    db = get_db()
    warn("Request url: %s" % request.url)
    if "?" in request.url and 'username' in request.args:
        username = request.args['username']    
    if not username and not userid:
        return render_template('user.html', has_user=False)
    if userid is None:
        userid = db.get_user_id(username.lower())
    if username is None:
        username = db.get_user_name(userid)
    err = None
    if username is None:
        err = "No username found for user with id = %s" % userid
    elif userid is None:
        err = "No userid found for user with name = %s" % username
    args = {
        'has_user': True,
        'err': err,
        'username': username,
        'userid': userid,
        'points': {'frame': 86400, 'data': db.get_user_score_graph(userid, 86400)}
    }
    if not err:
        args['user_names'] = db.get_usernames(userid)
    return render_template('user.html', **args)
Beispiel #3
0
def render_best_to_post():
    db = get_db()
    args = {
        'hour_stats': db.get_avg_points_per_x('hour'),
        'day_stats': db.get_avg_points_per_x('dow')
    }
    return render_template('best_to_post.html', **args)
Beispiel #4
0
def render_stats():
    db = get_db()
    args = {
        'posts_indexed': db.get_post_count(),
        'usernames_indexed': db.get_usernames_count(),
        'oldest_post': db.get_oldest_post(),
        'tags_indexed': db.get_tags_count(),
        'last_update': db.get_last_update()
    }
    return render_template('stats.html', **args)
Beispiel #5
0
def render_tope_title(frame='day'):
    if not frame in _flookup:
        return NotFound()
    db = get_db()
    args = {
        'timeframe': frame,
        'data': db.get_top_title_words(_flookup[frame], 50),
        'titles': _ftitle_words
    }
    return render_template('top_title.html', **args)
Beispiel #6
0
def render_user(frame='day'):
    if not frame in _flookup:
        return NotFound()
    db = get_db()
    args = {
        'timeframe': frame,
        'data': db.get_top_poster(_flookup[frame], 25),
        'titles': _ftitle
    }
    return render_template('top_user.html', **args)
Beispiel #7
0
def render_title_word_graph(username=None, userid=None):
    db = get_db()
    # TODO: only allow up to x | and & and max length
    searches = []
    for i in range(5):
        w = request.args.get("words%i" % i)
        if w and len(w.strip()):
            searches.append(w.replace(" ", "+")) 
    
    info("Searches %s" % searches)
    
    #frame = 86400 * 7
    frame = 60 * 60 * 24
    # TODO: catch sysntax error in search term 
    args = {
        'data': [{'frame': frame, 'search': x, 'data': db.get_title_word_graph(x)} for x in searches]
    }
    return render_template('title_word_graph.html', **args)
Beispiel #8
0
def get_user_points():
    db = get_db()
    pass