Ejemplo n.º 1
0
def upload():
    try:
        # todo: sanitize this
        group_timestamp = request.form["timestamp"]
        base64_image = request.form["image"].replace("data:image/png;base64,", "")
        frame_count = int(request.form["frameCount"])
        image_data = base64.b64decode(base64_image)
        # how long to show each frame in ms
        delay_ms = int(request.form["frameDuration"])
        # create folder for this set of images with timestamp as folder name
        batch_dir = APP_PATH + "uploads/" + group_timestamp
        if not os.path.exists(batch_dir):
            os.mkdir(batch_dir)
        png_index = request.form["index"]
        file_name = png_index.zfill(3) + ".png"
        f = open(batch_dir + "/" + file_name, "w")
        f.write(image_data)
        f.close()
        response = {"message": "Upload successful"}
        # if there are frame_count files in the directory, we have gotten all the pngs
        # we need to make a gif
        if len(os.listdir(batch_dir)) == frame_count:
            gif_destination_file = APP_PATH + "gifs/" + group_timestamp + ".gif"
            delay_hundredths = delay_ms / 10
            gif_result = pngs_to_gif(batch_dir, gif_destination_file, delay_hundredths)

            if gif_result:
                # upload image to indgur
                gif_url = "/gifs/" + group_timestamp + ".gif"
                response["gif_url"] = gif_url
        return return_json(response)
    except Exception as e:
        print e
        return return_json({"error": "Upload failed"})
Ejemplo n.º 2
0
def get_gifs():
    gifs = os.listdir(APP_PATH + 'gifs/')
    gif_urls = []
    for filename in sorted(gifs, reverse=True):
        if '.gif' in filename:
            gif_urls.append('/gifs/' + filename)
    return return_json({'urls': gif_urls})
Ejemplo n.º 3
0
def winners():
    filenames = [
        "1374210541835.gif",
        "1374206136232.gif",
        "1374186213781.gif",
        "1374185178897.gif",
        "1374183688215.gif",
        "1374183650872.gif",
        "1374183179217.gif",
        "1374184430650.gif",
        "1374186330306.gif",
        "1374194548815.gif",
        "1374208461297.gif",
        "1374210830057.gif",
        "1374212657807.gif",
        "1374212817564.gif",
        "1374206885481.gif",
        "1374205848739.gif",
        "1374194458159.gif",
        "1374180198784.gif",
        "1374247757899.gif",
        "1374192031780.gif",
        "1374191203721.gif",
    ]
    gif_urls = []
    for name in filenames:
        gif_urls.append("/gifs/" + name)
    return return_json({"urls": gif_urls})
Ejemplo n.º 4
0
def get_gifs():
    gifs = os.listdir(APP_PATH + "gifs/")
    gif_urls = []
    for filename in sorted(gifs, reverse=True):
        if ".gif" in filename:
            gif_urls.append("/gifs/" + filename)
    return return_json({"urls": gif_urls})
Ejemplo n.º 5
0
def create_short_url():
    data = request.get_json(silent=True, force=True) or request.form
    if isinstance(data, str):
        url = data
        name = get_random_name()
        expiry = get_expiry()
    else:
        url = data.get('url')
        name = data.get('name') or get_random_name()
        expiry = data.get('expiry') or get_expiry()

    try:
        url = validate_url(url)
        name = validate_name(name)
        expiry = validate_expiry(expiry)
    except ValidationError as err:
        message = err.message
    else:
        write_url(name, url, expiry)
        message = urljoin(app.config.get('DOMAIN'), name)

    if return_json():
        return jsonify(message)
    return render_template('index.html',
                           expiries=get_expiries(),
                           message=message)
Ejemplo n.º 6
0
def home_page():
    if return_json():
        return jsonify("Hi, I'm abbr. "
                       "Usage: POST either a url as string or a dict with "
                       "'url' and optionally 'name' and 'expiry' "
                       "('%Y-%m-%d %H:%M:%S').")
    return render_template('index.html', expiries=get_expiries())
Ejemplo n.º 7
0
    def destory(self):
        tmp = json.loads(request.form['entries'])

        db_instance = self.model.query.filter_by(id=tmp['index']).first()
        self.db.session.delete(db_instance)
        self.db.session.commit()

        return return_json({"success": True})
Ejemplo n.º 8
0
def login():
    print(request.json)
    username = request.json["username"]
    password = request.json["password"]

    if username == "admin" and password == "111111":
        response = {"data": 20000}
    return return_json()
Ejemplo n.º 9
0
def get_info_or_404(short_url):
    url = get_url(short_url)
    if not url:
        return abort(404)
    detail = {'name': short_url, 'url': url}
    if return_json():
        return jsonify(detail)
    return render_template('detail.html', **detail)
Ejemplo n.º 10
0
def signup():
    email = request.form['email']
    if len(email) > 0 and '.' in email and '@' in email:
        try:
            email_obj = Email(email)
            db.session.add(email_obj)
            db.session.commit()
            return return_json({'message': 'Successfully signed up.'})
        except IntegrityError as e:
            app.logger.error(e)
            if 'Duplicate entry' in str(e):
                return return_json({'error': 'That email address has already been signed up.'})
            else:
                return return_json({'error': 'Something went wrong with the database. Try again later.'})
        except Exception as e:
            app.logger.error(e)
            return return_json({'error': 'Agh, something went wrong. Try again later.'})

    else:
        return return_json({'error': 'Please enter a valid email address.'})
Ejemplo n.º 11
0
def winners():
    filenames = [
        '1374210541835.gif', '1374206136232.gif', '1374186213781.gif',
        '1374185178897.gif', '1374183688215.gif', '1374183650872.gif',
        '1374183179217.gif', '1374184430650.gif', '1374186330306.gif',
        '1374194548815.gif', '1374208461297.gif', '1374210830057.gif',
        '1374212657807.gif', '1374212817564.gif', '1374206885481.gif',
        '1374205848739.gif', '1374194458159.gif', '1374180198784.gif',
        '1374247757899.gif', '1374192031780.gif', '1374191203721.gif'
    ]
    gif_urls = []
    for name in filenames:
        gif_urls.append('/gifs/' + name)
    return return_json({'urls': gif_urls})
Ejemplo n.º 12
0
def upload():
    try:
        #todo: sanitize this
        group_timestamp = request.form['timestamp']
        base64_image = request.form['image'].replace('data:image/png;base64,',
                                                     '')
        frame_count = int(request.form['frameCount'])
        image_data = base64.b64decode(base64_image)
        # how long to show each frame in ms
        delay_ms = int(request.form['frameDuration'])
        # create folder for this set of images with timestamp as folder name
        batch_dir = APP_PATH + 'uploads/' + group_timestamp
        if not os.path.exists(batch_dir):
            os.mkdir(batch_dir)
        png_index = request.form['index']
        file_name = png_index.zfill(3) + '.png'
        f = open(batch_dir + '/' + file_name, 'w')
        f.write(image_data)
        f.close()
        response = {'message': 'Upload successful'}
        # if there are frame_count files in the directory, we have gotten all the pngs
        # we need to make a gif
        if len(os.listdir(batch_dir)) == frame_count:
            gif_destination_file = APP_PATH + 'gifs/' + group_timestamp + '.gif'
            delay_hundredths = delay_ms / 10
            gif_result = pngs_to_gif(batch_dir, gif_destination_file,
                                     delay_hundredths)

            if gif_result:
                #upload image to indgur
                gif_url = '/gifs/' + group_timestamp + '.gif'
                response['gif_url'] = gif_url
        return return_json(response)
    except Exception as e:
        print e
        return return_json({'error': 'Upload failed'})
Ejemplo n.º 13
0
    def create(self):
        tmp = json.loads(request.form['entries'])

        db_instance = self.model()
        for attr in self.model_field_names:
            if attr in self.json_fields:
                setattr(db_instance, attr, json.dumps(tmp[attr]))
            else:
                setattr(db_instance, attr, tmp[attr])

        self.db.session.add(db_instance)
        self.db.session.commit()

        return return_json({
            'success': True,
            'entries': db_instance.dump()
        })
Ejemplo n.º 14
0
    def update(self):
        tmp = json.loads(request.form['entries'])

        db_instance = self.model.query.filter_by(id=tmp['index']).first()

        for attr in self.model_field_names:
            if attr in self.json_fields:
                setattr(db_instance, attr, json.dumps(tmp[attr]))
            else:
                setattr(db_instance, attr, tmp[attr])

        self.db.session.add(db_instance)
        self.db.session.commit()

        return return_json({
            "success": True,
            "entries": tmp
        })
Ejemplo n.º 15
0
    def list(self):
        result = []
        for model_instance in self.model.query.all():
            result.append(model_instance.dump())

        return return_json(result)
Ejemplo n.º 16
0
def getVPNServers():
    data = getVPNServersList()
    return return_json(data)