Created
July 2, 2015 17:58
-
-
Save Nama/c318c92109c8bf5c52c9 to your computer and use it in GitHub Desktop.
URL shortener, written in Python with flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
######################################################################################### | |
# # | |
'''A.T.S.P. Short-URL Controller''' # | |
# # | |
######################################################################################### | |
import cymysql | |
from flask import Flask, redirect | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return redirect("https://yamahi.eu/shorturl") | |
@app.route('/<url>') | |
def url(url): | |
conn = cymysql.connect(host='127.0.0.1', port=3306, user='login', passwd='pw', db='shorturl') | |
cur = conn.cursor() | |
cur.execute("SELECT * FROM `shorturls` WHERE `surl` = %s", (url)) | |
lurl = cur.fetchone() | |
if lurl: | |
return redirect(lurl[1]) | |
else: | |
return 'Wrong link' | |
cur.close() | |
conn.close() | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', | |
port=63234,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment