コード例 #1
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def shortly():
    error = None
    url = ""
    shortly_count = db.get("shortly-count") or "0"
    if request.method == "POST":
        url = request.form["url"]
        if not is_valid_url(url):
            error = "Invalid URL"
        else:
            short_id = shorten(url)
            return short_id
    return render_template("shortly.html", error=error, url=url, shortly_count=shortly_count)
コード例 #2
0
def shortly():
    error = None
    url = ''
    shortly_count = db.get('shortly-count') or '0'
    if request.method == 'POST':
        url = request.form['url']
        if not is_valid_url(url):
            error = 'Invalid URL'
        else:
            short_id = shorten(url)
            return short_id
    return render_template('shortly.html', error=error, url=url, 
                                           shortly_count=shortly_count)
コード例 #3
0
ファイル: views.py プロジェクト: bearzk/shortly
def shortly():
    error = None
    url = ''
    shortly_count = db.get('shortly-count') or '0'
    if request.method == 'POST':
        url = request.form['url']
        if not is_valid_url(url):
            error = 'Invalid URL'
        else:
            short_id = shorten(url)
            return short_id
    return render_template('shortly.html', error=error, url=url, 
                                           shortly_count=shortly_count)
コード例 #4
0
def shorten(url):
    """Simple shorten logic.
    `original-short` + url will store the short id.
    `short-original` + short_id will store the corresponding original url.

    :param url: The original url you want to shorten.
    """
    short_id = db.get('original-short:' + url)
    if short_id is not None:
        return short_id
    num = db.incr('url-autoincr-id')
    short_id = base52_encode(num)
    db.set('original-short:' + url, short_id)
    db.set('short-original:' + short_id, url)
    return short_id
コード例 #5
0
ファイル: views.py プロジェクト: bearzk/shortly
def shorten(url):
    """Simple shorten logic.
    `original-short` + url will store the short id.
    `short-original` + short_id will store the corresponding original url.

    :param url: The original url you want to shorten.
    """
    short_id = db.get('original-short:' + url)
    if short_id is not None:
        return short_id
    num = db.incr('url-autoincr-id')
    short_id = base52_encode(num)
    db.set('original-short:' + url, short_id)
    db.set('short-original:' + short_id, url)
    return short_id
コード例 #6
0
def original(short_id):
    original_url = db.get('short-original:' + short_id)
    if original_url is None:
        abort(404)
    db.incr('shortly-count')
    return redirect(original_url)
コード例 #7
0
ファイル: views.py プロジェクト: bearzk/shortly
def original(short_id):
    original_url = db.get('short-original:' + short_id)
    if original_url is None:
        abort(404)
    db.incr('shortly-count')
    return redirect(original_url)