Exemple #1
0
    def update_posts_loop(cls):
        Database.initialize()

        while True:
            pulls = Pull.all_pulls()
            cls.update_posts(pulls)
            time.sleep(3600)
Exemple #2
0
def get_all_posts():
    user = User.get_by_email(session['email'])
    pulls = Pull.find_by_author_id(user.id)
    posts = []
    for pull in pulls:
        posts = posts + Post.from_mongo(pull._id)
    return render_template('all_posts.html', posts=posts)
Exemple #3
0
def refresh():
    posts = request.args.get('post')
    pull = request.args.get('pull')
    template = 'pulls.html'
    user = User.get_by_email(session['email'])
    pulls = Pull.find_by_author_id(user.id)
    ScheduledTasks.update_posts(pulls)
    return render_template(template, posts=posts, pull=pull, pulls=pulls)
Exemple #4
0
def price_drops():
    user = User.get_by_email(session['email'])
    pulls = Pull.find_by_author_id(user.id)
    posts_list = []
    for pull in pulls:
        posts = Post.from_mongo(pull._id)
        for post in posts:
            if len(post.prices) > 1:
                posts_list.append(post)
    return render_template('price_drops.html', posts=posts_list)
Exemple #5
0
def starred_posts():
    user = User.get_by_email(session['email'])
    pulls = Pull.find_by_author_id(user.id)
    posts = []
    for pull in pulls:
        try:
            posts = posts + Post.get_starred_posts(pull._id)
        except TypeError:
            continue
    return render_template('starred_posts.html', posts=posts)
Exemple #6
0
def start_pull():
    user = User.get_by_email(session['email'])
    pulls = Pull.find_by_author_id(user.id)
    return render_template('pulls.html', pulls=pulls)
Exemple #7
0
def edit_pull(change, pull_id):
    if change == 'delete':
        pull = Pull.from_mongo(pull_id)
        pull.delete_pull()
    return make_response(start_pull())
Exemple #8
0
def change_flags(variable, flag, post_id, template):
    post = Post.from_mongo_post_id(post_id)
    if flag == 'True':
        flag = True
    else:
        flag = False
    if variable == 'star':
        post.update_post({
            "_id": post._id,
            "location": post.location,
            "kms": post.kms,
            "image": post.image,
            "title": post.title,
            "date_posted": post.date_posted,
            "seller": post.seller,
            "prices": post.prices,
            "transmission": post.transmission,
            "description": post.description,
            "url": post.url,
            "pull_id": post.pull_id,
            "hide": post.hide,
            "star": flag,
            "type": post.type
        })
    else:
        post.update_post({
            "_id": post._id,
            "location": post.location,
            "kms": post.kms,
            "image": post.image,
            "title": post.title,
            "date_posted": post.date_posted,
            "seller": post.seller,
            "prices": post.prices,
            "transmission": post.transmission,
            "description": post.description,
            "url": post.url,
            "pull_id": post.pull_id,
            "hide": flag,
            "star": post.star,
            "type": post.type
        })
    if template == 'starred_posts.html':
        user = User.get_by_email(session['email'])
        pulls = Pull.find_by_author_id(user.id)
        posts = []
        for pull in pulls:
            try:
                posts = posts + Post.get_starred_posts(pull._id)
            except TypeError:
                continue
    else:
        pull = Pull.from_mongo(post.pull_id)
        posts = Post.from_mongo(pull._id)
    if template == 'posts.html':
        return make_response(load_posts(pull._id))
    elif template == 'all_posts.html':
        return make_response(get_all_posts())
    elif template == 'starred_posts.html':
        make_response(starred_posts())
    elif template == 'price_drops.html':
        make_response(price_drops())
    else:
        return render_template(template, pull=pull, posts=posts)
Exemple #9
0
def load_posts(pull_id):
    pull = Pull.from_mongo(pull_id)
    posts = Post.from_mongo(pull_id)
    return render_template('posts.html', pull=pull, posts=posts)
Exemple #10
0
def pull_final(make, model, pull_id):
    body_types = request.args.get('body_types')
    if body_types == "Select":
        body_types = ""
    transmissions = request.args.getlist('transmission')
    min_price = request.args.get('min_price')
    max_price = request.args.get('max_price')
    min_kms = request.args.get('min_kms')
    max_kms = request.args.get('max_kms')
    min_year = request.args.get('min_year')
    max_year = request.args.get('max_year')
    mandatory_keywords = request.args.get('mandatory_keywords')
    mandatory_keywords = mandatory_keywords.split()
    optional_keywords = request.args.get('optional_keywords')
    optional_keywords = optional_keywords.split()
    user = User.get_by_email(session['email'])
    pull_id = None if pull_id == 'None' else pull_id
    pull = Pull(_id=pull_id,
                author_id=user._id,
                type="autos",
                make=make,
                model=model,
                body_types=body_types,
                transmissions=transmissions,
                min_price=min_price,
                max_price=max_price,
                min_kms=min_kms,
                max_kms=max_kms,
                min_year=min_year,
                max_year=max_year,
                mandatory_keywords=mandatory_keywords,
                optional_keywords=optional_keywords)
    if pull_id is None:
        pull.generate_kijiji_url()
        pull.generate_autotrader_url()
        pull.save_to_mongo()
        pull.body_types
    else:
        pull.generate_kijiji_url()
        pull.generate_autotrader_url()
        old_pull = Pull.from_mongo(pull_id)
        old_pull.update_pull(pull.json())
        pull = old_pull
    pull.generate_kijiji_posts_data(new_or_update='new')
    pull.generate_autotrader_posts_data(new_or_update='new')
    return make_response(start_pull())