Show DevBest Pynozz, Flask-based URL Shortener

PousseyWashington

why did I buy an upgrade
Apr 29, 2014
31
12
I recently made a simple URL shortener in Flask.

Some of the features include:
  • Database rate limiting
  • JSON mini-API
  • Ban support
  • URL previewing
Here are a few screenshots and a code preview.
(keep in mind that I suck at designing and this was made in 5 minutes)
UDHWcJo.png


SAgjQBl.png


4i3qtkg.png


Yq08gHB.png


PHP:
@app.route('/api/generate_url', methods=['POST'])
def generate_url():
    long_url = request.form['url']
    ip = request.remote_addr

    if check_for_ban(ip) == True:
        return jsonify(success='False', message='You have been banned due to misuse of this service.')

    if url_for('index', _external=True) in long_url:
        return jsonify(success='False', message='You are not allowed to shorten local links.')

    if len(long_url) >= 1000:
        return jsonify(success='False', message='Your URL is over 1000 characters.')

    if not re.match('https?://', long_url) or ' ' in long_url:
        return jsonify(success='False', message='Your URL is invalid.')

    while True:
        short_url = ''.join(random.choice(string.letters + string.digits) for x in range(4))
        url = check_for_short_url(short_url)
        if url == False: break

    cursor = conn.cursor()

    cursor.execute("SELECT COUNT(1) FROM rate_limits WHERE ip = '%s'" % ip)
    if not cursor.fetchone()[0]:
        cursor.execute("INSERT INTO rate_limits (ip) VALUES ('%s')" % ip)
    else:
        cursor.execute("SELECT amount FROM rate_limits WHERE ip = '%s'" % ip)
        amount = cursor.fetchone()[0]
        if amount == 0:
            return jsonify(success='False', message='You have shortened too many URLs today. Try again tomorrow.')

        cursor.execute("UPDATE rate_limits SET amount = amount -1 WHERE ip = '%s'" % ip)

    cursor.execute("INSERT INTO urls (long_url, short_url, ip) VALUES ('%s', '%s', '%s')" % (long_url, short_url, ip))

    conn.commit()
    cursor.close()

    return jsonify(success='True', url=url_for('index', _external=True) + short_url, message='Your URL was created!')

You can find the source on my . It includes installation information along with the license.
 
Last edited:

Hindi

System.out.println(" ");
Dec 30, 2012
989
193
And it's unique, How?

There's tons of scripts for free, So why would someone use this?
  • You can add image uploader script just one like chevereto (Not that complicated)
  • You can do a mobile app along with this using same database regardless of iOS or android.
  • You can create user system, Show users which URL they have visited or whatsoever.
Thought this would help you with further development.
 

Sysode

Front-End Developer
Dec 11, 2012
1,673
848
And it's unique, How?

There's tons of scripts for free, So why would someone use this?
  • You can add image uploader script just one like chevereto (Not that complicated)
  • You can do a mobile app along with this using same database regardless of iOS or android.
  • You can create user system, Show users which URL they have visited or whatsoever.
Thought this would help you with further development.
He never said it was unique - maybe this was an educational project and now he's releasing to free so others can learn from it?

Anyways, nice release. Looks boring as fuck from my POV ;p
 

PousseyWashington

why did I buy an upgrade
Apr 29, 2014
31
12
He never said it was unique - maybe this was an educational project and now he's releasing to free so others can learn from it?

Anyways, nice release. Looks boring as fuck from my POV ;p
Right now it's more of an alpha project to me more than anything. I plan to add more features and improve the included index in the future, however, all constructive criticism is appreciated.
 

Users who are viewing this thread

Top