Commit 5cae76c1 authored by Emanuele Santoro's avatar Emanuele Santoro

Merge branch 'master' into database

parents 7b2462b1 dca3b58e
*~
__pycache__
*_ENV.sh
web: python3 musho.py
# web: python3 musho.py
web: gunicorn musho:musho --preload -b 0.0.0.0:$PORT --log-file -
\ No newline at end of file
......@@ -6,6 +6,8 @@ musho = Flask(__name__)
links = dict()
page_cache = dict()
musho_url = "http://localhost:9000"
debug = None
def page(path) :
if path not in page_cache :
......@@ -13,47 +15,48 @@ def page(path) :
page_cache[path] = contents
return page_cache[path]
@mush.route("/")
@musho.route("/")
def index() :
return page("templates/index.html")
#return open("views/index.html", "r").read()
@mush.route("/save", methods=['POST'])
@musho.route("/save", methods=['POST'])
def saveLink() :
url = request.form["url"]
hash = hashlib.new('sha1')
hash.update(url.encode('ascii','ignore'))
digest = hash.hexdigest()
short_url = digest[0:8]
links[short_url] = url
full_url = "http://localhost:9000/l/" + short_url
full_url = musho_url +"/l/" + short_url
return render_template('shortened_link.html', url=full_url)
@mush.route("/l/<string:link_id>")
@musho.route("/l/<string:link_id>")
def resolveLink(link_id):
if debug:
print("Risolvo il link '%s'" % link_id)
if link_id in links :
url = links[link_id]
return redirect(url)
else :
if debug:
print("Link non trovato")
print("contenuto del db:")
print(links)
return redirect("/")
debug = os.getenv("DEBUG", None)
if debug is not None :
musho.debug = True
port = 9000
try :
port = int(os.getenv("PORT", "9000"))
except :
pass
musho_url = os.getenv("MUSHO_URL", "http://localhost:%d" % port)
print("MUSHO_URL:\t\t%s" % musho_url)
print("PORT:\t\t\t%d" % port)
print("DEBUG:\t\t\t%s" % debug)
if __name__ == "__main__" :
debug = os.getenv("DEBUG", None)
if debug is not None :
mush.debug = True
port = 9000
try :
port = int(os.getenv("PORT", "9000"))
except :
pass
musho.run(port=port)
python-3.4.0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment