from flask import Flask, request
import urllib.parse

from urlshort import URLShortener

app = Flask(__name__)

@app.route("/", methods=('GET', 'POST'))
def hash_url():
    """ return hashed url """
    url = request.args.get("url")
    us = URLShortener(5, "http://pybit.es")

    if url:
        short_url = us.get_dst_url(url)
        hash_value = us.get_hash(url)
        netloc = urllib.parse.urlparse(url).netloc

        us.save_mapping(url, short_url, netloc, hash_value)
        us.save_visit(url, short_url)
        return "Url Converted: {}".format(short_url)
    else:
        return "."

if __name__ == '__main__':
    app.run(host="0.0.0.0")


from flask import Flask, request
import urllib.parse

from urlshort import URLShortener

app = Flask(__name__)

@app.route("/", methods=('GET', 'POST'))
def hash_url():
    """ return hashed url """
    url = request.args.get("url")
    us = URLShortener(5, "http://pybit.es")

    if url:
        short_url = us.get_dst_url(url)
        hash_value = us.get_hash(url)
        netloc = urllib.parse.urlparse(url).netloc

        us.save_mapping(url, short_url, netloc, hash_value)
        us.save_visit(url, short_url)
        return "Url Converted: {}".format(short_url)
    else:
        return "."

if __name__ == '__main__':
    app.run(host="0.0.0.0")


return hashed url