Esempio n. 1
0
def home():
    # This function is executed when http://example.com/ is requested. It
    # works with two methods - GET and POST. When URL is submitted via POST
    # method, then it catches it and show the regarding short URL or regarding
    # errors.

    number = number_of_generated_short_url()
    if request.method == 'POST':
        form = GetLinkForm(request.form)
        if form.validate():
            long_url = form.long_url.data
            checker = url_checker(long_url)
            if checker is True:
                short_url = short_url_generator(long_url)
                return render_template('index.html',
                                       form=form,
                                       short_url=short_url,
                                       number=number)
            else:
                flash("The URL seems to be dead at this moment.")
                return render_template('index.html', form=form, number=number)
        else:
            flash("Please, paste a valid link to shorten it.")
            return render_template('index.html', form=form, number=number)

    else:
        return render_template('index.html', form=GetLinkForm(), number=number)
Esempio n. 2
0
def apiv10(long_url):
    # This is our Version-1.0 API function. It will take the long_url as
    # parameter then return two different dictionary based on url_checker
    # function output.
    checker = url_checker(long_url)
    if checker is True:
        short_url = short_url_generator(long_url)
        return {
            'state': 'ok',
            'long_url': long_url,
            'short_url': short_url,
            'message': ''
        }
    else:
        error = "The URL seems to be dead at this moment."
        return {
            'state': 'error',
            'long_url': long_url,
            'short_url': '',
            'message': error
        }
Esempio n. 3
0
def home():
    # This function is executed when http://example.com/ is requested. It
    # works with two methods - GET and POST. When URL is submitted via POST
    # method, then it catches it and show the regarding short URL or regarding
    # errors.

    number = number_of_generated_short_url()
    if request.method == "POST":
        form = GetLinkForm(request.form)
        if form.validate():
            long_url = form.long_url.data
            checker = url_checker(long_url)
            if checker is True:
                short_url = short_url_generator(long_url)
                return render_template("index.html", form=form, short_url=short_url, number=number)
            else:
                flash("The URL seems to be dead at this moment.")
                return render_template("index.html", form=form, number=number)
        else:
            flash("Please, paste a valid link to shorten it.")
            return render_template("index.html", form=form, number=number)

    else:
        return render_template("index.html", form=GetLinkForm(), number=number)