示例#1
0
def refresh(siteid=-1):
    if siteid >= 0:
        site = Site.query.filter(Site.id == siteid).first()
        capture(site)
        resize(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots', '%s.png' % site.id))
        site.screenshot = '%s.png' % site.id
        db.session.commit()
        return redirect(url_for('index', catid=site.id_cat))
    else:
        return ""
示例#2
0
def add(catid):
    categories = Category.query.order_by(Category.order, Category.title).all()

    if request.method == 'GET':
        return render_template('add.html', current_cat=catid, categories=categories)
    elif request.method == 'POST':
        last = Site.query.filter(Site.id_cat == catid).order_by(Site.order.desc()).first()
        if last is None or last.order is None:
            last = 0
        else:
            last = last.order
        site = Site(request.form['url'], request.form['title'], last + 1, catid)
        db.session.add(site)
        db.session.commit()

        capture(site)
        resize(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots/', '%s.png' % site.id))

        site.screenshot = '%s.png' % site.id
        db.session.commit()
        return redirect(url_for('index', catid=catid))
示例#3
0
def upload(siteid=-1):
    if siteid >= 0:
        categories = Category.query.order_by(Category.order, Category.title).all()
        site = Site.query.filter(Site.id == siteid).first()

        if request.method == 'GET':
            return render_template('upload.html', current_cat=site.id_cat, categories=categories)
        elif request.method == 'POST':
            capture = request.files['capture']
            if capture and '.' in capture.filename and capture.filename.rsplit('.', 1)[1] in ['jpg', 'png', 'gif']:
                filename = secure_filename(capture.filename)
                try:
                    os.unlink(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots', site.screenshot))
                except:
                    pass
                capture.save(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots', '%s.png' % site.id))
                resize(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/screenshots', '%s.png' % site.id))

                site.screenshot = '%s.png' % site.id
                db.session.commit()
                return redirect(url_for('index', catid=site.id_cat))
    else:
        return ""